[FFmpeg-cvslog] ffmpeg: add -(no)find_stream_info expert option

2017-07-18 Thread Clément Bœsch
ffmpeg | branch: master | Clément Bœsch  | Wed Jul 12 11:06:52 
2017 +0200| [b7a741223df52632fba35718525fb18d0d2792d7] | committer: Clément 
Bœsch

ffmpeg: add -(no)find_stream_info expert option

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

 ffmpeg_opt.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 989391bb34..610082de17 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -145,6 +145,7 @@ static int override_ffserver  = 0;
 static int input_stream_potentially_available = 0;
 static int ignore_unknown_streams = 0;
 static int copy_unknown_streams = 0;
+static int find_stream_info = 1;
 
 static void uninit_options(OptionsContext *o)
 {
@@ -949,10 +950,8 @@ static int open_input_file(OptionsContext *o, const char 
*filename)
 AVInputFormat *file_iformat = NULL;
 int err, i, ret;
 int64_t timestamp;
-AVDictionary **opts;
 AVDictionary *unused_opts = NULL;
 AVDictionaryEntry *e = NULL;
-int orig_nb_streams; // number of streams before 
avformat_find_stream_info
 char *   video_codec_name = NULL;
 char *   audio_codec_name = NULL;
 char *subtitle_codec_name = NULL;
@@ -1055,13 +1054,19 @@ static int open_input_file(OptionsContext *o, const 
char *filename)
 for (i = 0; i < ic->nb_streams; i++)
 choose_decoder(o, ic, ic->streams[i]);
 
-/* Set AVCodecContext options for avformat_find_stream_info */
-opts = setup_find_stream_info_opts(ic, o->g->codec_opts);
-orig_nb_streams = ic->nb_streams;
+if (find_stream_info) {
+AVDictionary **opts = setup_find_stream_info_opts(ic, 
o->g->codec_opts);
+int orig_nb_streams = ic->nb_streams;
 
+// TODO: reindent
 /* If not enough info to get the stream parameters, we decode the
first frames to get it. (used in mpeg case for example) */
 ret = avformat_find_stream_info(ic, opts);
+
+for (i = 0; i < orig_nb_streams; i++)
+av_dict_free(&opts[i]);
+av_freep(&opts);
+
 if (ret < 0) {
 av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", 
filename);
 if (ic->nb_streams == 0) {
@@ -1069,6 +1074,7 @@ static int open_input_file(OptionsContext *o, const char 
*filename)
 exit_program(1);
 }
 }
+}
 
 if (o->start_time_eof != AV_NOPTS_VALUE) {
 if (ic->duration>0) {
@@ -1180,10 +1186,6 @@ static int open_input_file(OptionsContext *o, const char 
*filename)
 }
 }
 
-for (i = 0; i < orig_nb_streams; i++)
-av_dict_free(&opts[i]);
-av_freep(&opts);
-
 input_stream_potentially_available = 1;
 
 return 0;
@@ -3520,6 +3522,8 @@ const OptionDef options[] = {
 { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | 
OPT_INPUT,
  { .off = 
OFFSET(thread_queue_size) },
 "set the maximum number of queued packets from the demuxer" },
+{ "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { 
&find_stream_info },
+"read and decode the streams to fill missing information with 
heuristics" },
 
 /* video options */
 { "vframes",  OPT_VIDEO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT, 
  { .func_arg = opt_video_frames },

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


[FFmpeg-cvslog] ffplay: reindent after previous commit

2017-07-18 Thread Clément Bœsch
ffmpeg | branch: master | Clément Bœsch  | Tue Jul 18 10:24:48 
2017 +0200| [af50fbaaeb6881d91e9d6b5fcdc56468c0b17ec2] | committer: Clément 
Bœsch

ffplay: reindent after previous commit

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

 ffplay.c | 21 ++---
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/ffplay.c b/ffplay.c
index 2eaeebc826..7cc5ab1644 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -2749,19 +2749,18 @@ static int read_thread(void *arg)
 AVDictionary **opts = setup_find_stream_info_opts(ic, codec_opts);
 int orig_nb_streams = ic->nb_streams;
 
-// TODO: reindent
-err = avformat_find_stream_info(ic, opts);
+err = avformat_find_stream_info(ic, opts);
 
-for (i = 0; i < orig_nb_streams; i++)
-av_dict_free(&opts[i]);
-av_freep(&opts);
+for (i = 0; i < orig_nb_streams; i++)
+av_dict_free(&opts[i]);
+av_freep(&opts);
 
-if (err < 0) {
-av_log(NULL, AV_LOG_WARNING,
-   "%s: could not find codec parameters\n", is->filename);
-ret = -1;
-goto fail;
-}
+if (err < 0) {
+av_log(NULL, AV_LOG_WARNING,
+   "%s: could not find codec parameters\n", is->filename);
+ret = -1;
+goto fail;
+}
 }
 
 if (ic->pb)

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


[FFmpeg-cvslog] ffmpeg: reindent after previous commit

2017-07-18 Thread Clément Bœsch
ffmpeg | branch: master | Clément Bœsch  | Tue Jul 18 10:24:40 
2017 +0200| [d7ea14c5e22891b09d14a1e3cde5358146e32a40] | committer: Clément 
Bœsch

ffmpeg: reindent after previous commit

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

 ffmpeg_opt.c | 25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 610082de17..1c4a11ef21 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -1058,23 +1058,22 @@ static int open_input_file(OptionsContext *o, const 
char *filename)
 AVDictionary **opts = setup_find_stream_info_opts(ic, 
o->g->codec_opts);
 int orig_nb_streams = ic->nb_streams;
 
-// TODO: reindent
-/* If not enough info to get the stream parameters, we decode the
-   first frames to get it. (used in mpeg case for example) */
-ret = avformat_find_stream_info(ic, opts);
+/* If not enough info to get the stream parameters, we decode the
+   first frames to get it. (used in mpeg case for example) */
+ret = avformat_find_stream_info(ic, opts);
 
-for (i = 0; i < orig_nb_streams; i++)
-av_dict_free(&opts[i]);
-av_freep(&opts);
+for (i = 0; i < orig_nb_streams; i++)
+av_dict_free(&opts[i]);
+av_freep(&opts);
 
-if (ret < 0) {
-av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", 
filename);
-if (ic->nb_streams == 0) {
-avformat_close_input(&ic);
-exit_program(1);
+if (ret < 0) {
+av_log(NULL, AV_LOG_FATAL, "%s: could not find codec 
parameters\n", filename);
+if (ic->nb_streams == 0) {
+avformat_close_input(&ic);
+exit_program(1);
+}
 }
 }
-}
 
 if (o->start_time_eof != AV_NOPTS_VALUE) {
 if (ic->duration>0) {

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


[FFmpeg-cvslog] ffplay: add -(no)find_stream_info expert option

2017-07-18 Thread Clément Bœsch
ffmpeg | branch: master | Clément Bœsch  | Wed Jul 12 11:06:54 
2017 +0200| [998687f1b23d2899d9975834faf3a2aed2f335ee] | committer: Clément 
Bœsch

ffplay: add -(no)find_stream_info expert option

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

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

diff --git a/ffplay.c b/ffplay.c
index c0b326c8cc..2eaeebc826 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -349,6 +349,7 @@ static int nb_vfilters = 0;
 static char *afilters = NULL;
 #endif
 static int autorotate = 1;
+static int find_stream_info = 1;
 
 /* current context */
 static int is_full_screen;
@@ -2695,8 +2696,6 @@ static int read_thread(void *arg)
 int64_t stream_start_time;
 int pkt_in_play_range = 0;
 AVDictionaryEntry *t;
-AVDictionary **opts;
-int orig_nb_streams;
 SDL_mutex *wait_mutex = SDL_CreateMutex();
 int scan_all_pmts_set = 0;
 int64_t pkt_ts;
@@ -2746,9 +2745,11 @@ static int read_thread(void *arg)
 
 av_format_inject_global_side_data(ic);
 
-opts = setup_find_stream_info_opts(ic, codec_opts);
-orig_nb_streams = ic->nb_streams;
+if (find_stream_info) {
+AVDictionary **opts = setup_find_stream_info_opts(ic, codec_opts);
+int orig_nb_streams = ic->nb_streams;
 
+// TODO: reindent
 err = avformat_find_stream_info(ic, opts);
 
 for (i = 0; i < orig_nb_streams; i++)
@@ -2761,6 +2762,7 @@ static int read_thread(void *arg)
 ret = -1;
 goto fail;
 }
+}
 
 if (ic->pb)
 ic->pb->eof_reached = 0; // FIXME hack, ffplay maybe should not use 
avio_feof() to test for the end
@@ -3557,6 +3559,8 @@ static const OptionDef options[] = {
 { "scodec", HAS_ARG | OPT_STRING | OPT_EXPERT, { &subtitle_codec_name }, 
"force subtitle decoder", "decoder_name" },
 { "vcodec", HAS_ARG | OPT_STRING | OPT_EXPERT, {&video_codec_name }, 
"force video decoder","decoder_name" },
 { "autorotate", OPT_BOOL, { &autorotate }, "automatically rotate video", 
"" },
+{ "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT, { 
&find_stream_info },
+"read and decode the streams to fill missing information with 
heuristics" },
 { NULL, },
 };
 

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


[FFmpeg-cvslog] ffprobe: add -(no)find_stream_info expert option

2017-07-18 Thread Clément Bœsch
ffmpeg | branch: master | Clément Bœsch  | Wed Jul 12 11:06:53 
2017 +0200| [8e0d5b354e70eb1d386e9f459a876dfdc9367591] | committer: Clément 
Bœsch

ffprobe: add -(no)find_stream_info expert option

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

 ffprobe.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index e295c53def..72a06d983b 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -130,6 +130,8 @@ typedef struct ReadInterval {
 static ReadInterval *read_intervals;
 static int read_intervals_nb = 0;
 
+static int find_stream_info  = 1;
+
 /* section structure definition */
 
 #define SECTION_MAX_NB_CHILDREN 10
@@ -2771,10 +2773,9 @@ static void show_error(WriterContext *w, int err)
 
 static int open_input_file(InputFile *ifile, const char *filename)
 {
-int err, i, orig_nb_streams;
+int err, i;
 AVFormatContext *fmt_ctx = NULL;
 AVDictionaryEntry *t;
-AVDictionary **opts;
 int scan_all_pmts_set = 0;
 
 fmt_ctx = avformat_alloc_context();
@@ -2802,10 +2803,11 @@ static int open_input_file(InputFile *ifile, const char 
*filename)
 return AVERROR_OPTION_NOT_FOUND;
 }
 
-/* fill the streams in the format context */
-opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
-orig_nb_streams = fmt_ctx->nb_streams;
+if (find_stream_info) {
+AVDictionary **opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
+int orig_nb_streams = fmt_ctx->nb_streams;
 
+// TODO: reindent
 err = avformat_find_stream_info(fmt_ctx, opts);
 
 for (i = 0; i < orig_nb_streams; i++)
@@ -2816,6 +2818,7 @@ static int open_input_file(InputFile *ifile, const char 
*filename)
 print_error(filename, err);
 return err;
 }
+}
 
 av_dump_format(fmt_ctx, 0, filename, 0);
 
@@ -3472,6 +3475,8 @@ static const OptionDef real_options[] = {
 { "read_intervals", HAS_ARG, {.func_arg = opt_read_intervals}, "set read 
intervals", "read_intervals" },
 { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = 
opt_default}, "generic catch all option", "" },
 { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", 
"input_file"},
+{ "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT, { 
&find_stream_info },
+"read and decode the streams to fill missing information with 
heuristics" },
 { NULL, },
 };
 

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


[FFmpeg-cvslog] ffprobe: reindent after previous commit

2017-07-18 Thread Clément Bœsch
ffmpeg | branch: master | Clément Bœsch  | Tue Jul 18 10:24:55 
2017 +0200| [dad54e3c29dc1763b52d516a9d25722c3b4623e7] | committer: Clément 
Bœsch

ffprobe: reindent after previous commit

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

 ffprobe.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index 72a06d983b..f6d9be0df9 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -2807,17 +2807,16 @@ static int open_input_file(InputFile *ifile, const char 
*filename)
 AVDictionary **opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
 int orig_nb_streams = fmt_ctx->nb_streams;
 
-// TODO: reindent
-err = avformat_find_stream_info(fmt_ctx, opts);
+err = avformat_find_stream_info(fmt_ctx, opts);
 
-for (i = 0; i < orig_nb_streams; i++)
-av_dict_free(&opts[i]);
-av_freep(&opts);
+for (i = 0; i < orig_nb_streams; i++)
+av_dict_free(&opts[i]);
+av_freep(&opts);
 
-if (err < 0) {
-print_error(filename, err);
-return err;
-}
+if (err < 0) {
+print_error(filename, err);
+return err;
+}
 }
 
 av_dump_format(fmt_ctx, 0, filename, 0);

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


[FFmpeg-cvslog] lavc/jpeg2000dec: Read the sample aspect ratio from the jp2 resolution box.

2017-07-18 Thread Carl Eugen Hoyos
ffmpeg | branch: master | Carl Eugen Hoyos  | Tue May  2 
16:27:47 2017 +0200| [4c1aac893c27cba0388e5337552b49f0c75e8178] | committer: 
Carl Eugen Hoyos

lavc/jpeg2000dec: Read the sample aspect ratio from the jp2 resolution box.

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

 libavcodec/jpeg2000dec.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index c3d2747675..b67efc76bb 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -26,6 +26,7 @@
  */
 
 #include 
+#include 
 
 #include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
@@ -106,6 +107,7 @@ typedef struct Jpeg2000DecoderContext {
 int tile_width, tile_height;
 unsignednumXtiles, numYtiles;
 int maxtilelen;
+AVRational  sar;
 
 Jpeg2000CodingStyle codsty[4];
 Jpeg2000QuantStyle  qntsty[4];
@@ -2058,6 +2060,34 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
 if (cn < 4 && asoc < 4)
 s->cdef[cn] = asoc;
 }
+} else if (atom2 == MKBETAG('r','e','s',' ') && atom2_size >= 
18) {
+int64_t vnum, vden, hnum, hden, vexp, hexp;
+uint32_t resx;
+bytestream2_skip(&s->g, 4);
+resx = bytestream2_get_be32u(&s->g);
+if (resx != MKBETAG('r','e','s','c') && resx != 
MKBETAG('r','e','s','d')) {
+bytestream2_seek(&s->g, atom2_end, SEEK_SET);
+continue;
+}
+vnum = bytestream2_get_be16u(&s->g);
+vden = bytestream2_get_be16u(&s->g);
+hnum = bytestream2_get_be16u(&s->g);
+hden = bytestream2_get_be16u(&s->g);
+vexp = bytestream2_get_byteu(&s->g);
+hexp = bytestream2_get_byteu(&s->g);
+if (vexp > hexp) {
+vexp -= hexp;
+hexp = 0;
+} else {
+hexp -= vexp;
+vexp = 0;
+}
+if (   INT64_MAX / (hnum * vden) > pow(10, hexp)
+&& INT64_MAX / (vnum * hden) > pow(10, vexp))
+av_reduce(&s->sar.den, &s->sar.num,
+  hnum * vden * pow(10, hexp),
+  vnum * hden * pow(10, vexp),
+  INT32_MAX);
 }
 bytestream2_seek(&s->g, atom2_end, SEEK_SET);
 } while (atom_end - atom2_end >= 8);
@@ -2140,6 +2170,9 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, 
void *data,
 
 if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
 memcpy(picture->data[1], s->palette, 256 * sizeof(uint32_t));
+if (s->sar.num && s->sar.den)
+avctx->sample_aspect_ratio = s->sar;
+s->sar.num = s->sar.den = 0;
 
 return bytestream2_tell(&s->g);
 

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


[FFmpeg-cvslog] avdevice/decklink_dec: add support for decoding teletext from 10bit ancillary data

2017-07-18 Thread Marton Balint
ffmpeg | branch: master | Marton Balint  | Sat Jun 24 16:57:18 
2017 +0200| [cc0916bfc27e2baba7747a7503bfd183d2e8bba0] | committer: Marton 
Balint

avdevice/decklink_dec: add support for decoding teletext from 10bit ancillary 
data

This also add supports for 4K DeckLink cards because they always output the
ancillary data in 10-bit.

v2:
- only try teletext decoding for 576i PAL mode
- some comments as requested by Aaron Levinson

Signed-off-by: Marton Balint 

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

 doc/indevs.texi  |  4 +--
 libavdevice/decklink_dec.cpp | 61 
 2 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 51c304f3ec..330617a7c9 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -250,8 +250,8 @@ specifically lines 6 to 22, and lines 318 to 335. Line 6 is 
the LSB in the mask.
 Selected lines which do not contain teletext information will be ignored. You
 can use the special @option{all} constant to select all possible lines, or
 @option{standard} to skip lines 6, 318 and 319, which are not compatible with 
all
-receivers. Capturing teletext only works for SD PAL sources in 8 bit mode.
-To use this option, ffmpeg needs to be compiled with @code{--enable-libzvbi}.
+receivers. Capturing teletext only works for SD PAL sources. To use this
+option, ffmpeg needs to be compiled with @code{--enable-libzvbi}.
 
 @item channels
 Defines number of audio channels to capture. Must be @samp{2}, @samp{8} or 
@samp{16}.
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 39974e3ff4..6783a0ce77 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -30,6 +30,7 @@ extern "C" {
 extern "C" {
 #include "config.h"
 #include "libavformat/avformat.h"
+#include "libavutil/avassert.h"
 #include "libavutil/avutil.h"
 #include "libavutil/common.h"
 #include "libavutil/imgutils.h"
@@ -54,21 +55,43 @@ static uint8_t calc_parity_and_line_offset(int line)
 return ret;
 }
 
-int teletext_data_unit_from_vbi_data(int line, uint8_t *src, uint8_t *tgt)
+static void fill_data_unit_head(int line, uint8_t *tgt)
+{
+tgt[0] = 0x02; // data_unit_id
+tgt[1] = 0x2c; // data_unit_length
+tgt[2] = calc_parity_and_line_offset(line); // field_parity, line_offset
+tgt[3] = 0xe4; // framing code
+}
+
+static uint8_t* teletext_data_unit_from_vbi_data(int line, uint8_t *src, 
uint8_t *tgt, vbi_pixfmt fmt)
 {
 vbi_bit_slicer slicer;
 
-vbi_bit_slicer_init(&slicer, 720, 1350, 6937500, 6937500, 0x00e4, 
0x, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, VBI_PIXFMT_UYVY);
+vbi_bit_slicer_init(&slicer, 720, 1350, 6937500, 6937500, 0x00e4, 
0x, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, fmt);
 
 if (vbi_bit_slice(&slicer, src, tgt + 4) == FALSE)
-return -1;
+return tgt;
 
-tgt[0] = 0x02; // data_unit_id
-tgt[1] = 0x2c; // data_unit_length
-tgt[2] = calc_parity_and_line_offset(line); // field_parity, line_offset
-tgt[3] = 0xe4; // framing code
+fill_data_unit_head(line, tgt);
 
-return 0;
+return tgt + 46;
+}
+
+static uint8_t* teletext_data_unit_from_vbi_data_10bit(int line, uint8_t *src, 
uint8_t *tgt)
+{
+uint8_t y[720];
+uint8_t *py = y;
+uint8_t *pend = y + 720;
+/* The 10-bit VBI data is packed in V210, but libzvbi only supports 8-bit,
+ * so we extract the 8 MSBs of the luma component, that is enough for
+ * teletext bit slicing. */
+while (py < pend) {
+*py++ = (src[1] >> 4) + ((src[2] & 15) << 4);
+*py++ = (src[4] >> 2) + ((src[5] & 3 ) << 6);
+*py++ = (src[6] >> 6) + ((src[7] & 63) << 2);
+src += 8;
+}
+return teletext_data_unit_from_vbi_data(line, y, tgt, VBI_PIXFMT_YUV420);
 }
 #endif
 
@@ -359,7 +382,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts);
 
 #if CONFIG_LIBZVBI
-if (!no_video && ctx->teletext_lines && videoFrame->GetPixelFormat() 
== bmdFormat8BitYUV && videoFrame->GetWidth() == 720) {
+if (!no_video && ctx->teletext_lines) {
 IDeckLinkVideoFrameAncillary *vanc;
 AVPacket txt_pkt;
 uint8_t txt_buf0[1611]; // max 35 * 46 bytes decoded teletext 
lines + 1 byte data_identifier
@@ -368,16 +391,22 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
 if (videoFrame->GetAncillaryData(&vanc) == S_OK) {
 int i;
 int64_t line_mask = 1;
+BMDPixelFormat vanc_format = vanc->GetPixelFormat();
 txt_buf[0] = 0x10;// data_identifier - EBU_data
 txt_buf++;
-for (i = 6; i < 336; i++, line_mask <<= 1) {
-uint8_t *buf;
-if ((ctx->teletext_lines & line_mask) && 
vanc->GetBuffer

[FFmpeg-cvslog] avdevice/decklink_dec: add support for receiving op47 teletext

2017-07-18 Thread Marton Balint
ffmpeg | branch: master | Marton Balint  | Sun Jun 18 02:34:11 
2017 +0200| [9b937958907daaddade139c36ce33c6eac269631] | committer: Marton 
Balint

avdevice/decklink_dec: add support for receiving op47 teletext

v2:
- use uint16_t instead of int to store 10-bit ancillary data
- fix ancillary line numbers for 1080p
- some comments and clarifications as requested by Aaron Levinson

Signed-off-by: Marton Balint 

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

 doc/indevs.texi  |  20 ---
 libavdevice/decklink_dec.cpp | 127 +++
 2 files changed, 129 insertions(+), 18 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 330617a7c9..09e33216dc 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -245,13 +245,19 @@ of uyvy422. Not all Blackmagic devices support this 
option.
 
 @item teletext_lines
 If set to nonzero, an additional teletext stream will be captured from the
-vertical ancillary data. This option is a bitmask of the VBI lines checked,
-specifically lines 6 to 22, and lines 318 to 335. Line 6 is the LSB in the 
mask.
-Selected lines which do not contain teletext information will be ignored. You
-can use the special @option{all} constant to select all possible lines, or
-@option{standard} to skip lines 6, 318 and 319, which are not compatible with 
all
-receivers. Capturing teletext only works for SD PAL sources. To use this
-option, ffmpeg needs to be compiled with @code{--enable-libzvbi}.
+vertical ancillary data. Both SD PAL (576i) and HD (1080i or 1080p)
+sources are supported. In case of HD sources, OP47 packets are decoded.
+
+This option is a bitmask of the SD PAL VBI lines captured, specifically lines 6
+to 22, and lines 318 to 335. Line 6 is the LSB in the mask. Selected lines
+which do not contain teletext information will be ignored. You can use the
+special @option{all} constant to select all possible lines, or
+@option{standard} to skip lines 6, 318 and 319, which are not compatible with
+all receivers.
+
+For SD sources, ffmpeg needs to be compiled with @code{--enable-libzvbi}. For
+HD sources, on older (pre-4K) DeckLink card models you have to capture in 10
+bit mode.
 
 @item channels
 Defines number of audio channels to capture. Must be @samp{2}, @samp{8} or 
@samp{16}.
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 6783a0ce77..8b5c1a20c1 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -36,6 +36,7 @@ extern "C" {
 #include "libavutil/imgutils.h"
 #include "libavutil/time.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/reverse.h"
 #if CONFIG_LIBZVBI
 #include 
 #endif
@@ -44,7 +45,6 @@ extern "C" {
 #include "decklink_common.h"
 #include "decklink_dec.h"
 
-#if CONFIG_LIBZVBI
 static uint8_t calc_parity_and_line_offset(int line)
 {
 uint8_t ret = (line < 313) << 5;
@@ -63,6 +63,7 @@ static void fill_data_unit_head(int line, uint8_t *tgt)
 tgt[3] = 0xe4; // framing code
 }
 
+#if CONFIG_LIBZVBI
 static uint8_t* teletext_data_unit_from_vbi_data(int line, uint8_t *src, 
uint8_t *tgt, vbi_pixfmt fmt)
 {
 vbi_bit_slicer slicer;
@@ -95,6 +96,95 @@ static uint8_t* teletext_data_unit_from_vbi_data_10bit(int 
line, uint8_t *src, u
 }
 #endif
 
+static uint8_t* teletext_data_unit_from_op47_vbi_packet(int line, uint16_t 
*py, uint8_t *tgt)
+{
+int i;
+
+if (py[0] != 0x255 || py[1] != 0x255 || py[2] != 0x227)
+return tgt;
+
+fill_data_unit_head(line, tgt);
+
+py += 3;
+tgt += 4;
+
+for (i = 0; i < 42; i++)
+   *tgt++ = ff_reverse[py[i] & 255];
+
+return tgt;
+}
+
+static int linemask_matches(int line, int64_t mask)
+{
+int shift = -1;
+if (line >= 6 && line <= 22)
+shift = line - 6;
+if (line >= 318 && line <= 335)
+shift = line - 318 + 17;
+return shift >= 0 && ((1ULL << shift) & mask);
+}
+
+static uint8_t* teletext_data_unit_from_op47_data(uint16_t *py, uint16_t 
*pend, uint8_t *tgt, int64_t wanted_lines)
+{
+if (py < pend - 9) {
+if (py[0] == 0x151 && py[1] == 0x115 && py[3] == 0x102) {   // 
identifier, identifier, format code for WST teletext
+uint16_t *descriptors = py + 4;
+int i;
+py += 9;
+for (i = 0; i < 5 && py < pend - 45; i++, py += 45) {
+int line = (descriptors[i] & 31) + (!(descriptors[i] & 128)) * 
313;
+if (line && linemask_matches(line, wanted_lines))
+tgt = teletext_data_unit_from_op47_vbi_packet(line, py, 
tgt);
+}
+}
+}
+return tgt;
+}
+
+static uint8_t* teletext_data_unit_from_ancillary_packet(uint16_t *py, 
uint16_t *pend, uint8_t *tgt, int64_t wanted_lines, int allow_multipacket)
+{
+uint16_t did = py[0];   // 
data id
+uint16_t sdid = py[1];  // 
secon

[FFmpeg-cvslog] opus: simplify coarse energy beta coefficients

2017-07-18 Thread Rostislav Pehlivanov
ffmpeg | branch: master | Rostislav Pehlivanov  | Tue Jul 
18 20:47:30 2017 +0100| [79450adfc80bb5d5d94deb1e1dd573b6cebfbe99] | committer: 
Rostislav Pehlivanov

opus: simplify coarse energy beta coefficients

Just put the subtraction in the table.

Signed-off-by: Rostislav Pehlivanov 

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

 libavcodec/opus_celt.c | 26 +++---
 libavcodec/opusenc.c   |  4 ++--
 libavcodec/opustab.c   |  4 ++--
 3 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c
index 0177b123b1..84d484753b 100644
--- a/libavcodec/opus_celt.c
+++ b/libavcodec/opus_celt.c
@@ -29,25 +29,21 @@
 #include "opustab.h"
 #include "opus_pvq.h"
 
+/* Use the 2D z-transform to apply prediction in both the time domain (alpha)
+ * and the frequency domain (beta) */
 static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc)
 {
 int i, j;
-float prev[2] = {0};
-float alpha, beta;
-const uint8_t *model;
-
-/* use the 2D z-transform to apply prediction in both */
-/* the time domain (alpha) and the frequency domain (beta) */
-
-if (opus_rc_tell(rc)+3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) {
-/* intra frame */
-alpha = 0;
-beta  = 1.0f - 4915.0f/32768.0f;
+float prev[2] = { 0 };
+float alpha = ff_celt_alpha_coef[f->size];
+float beta  = ff_celt_beta_coef[f->size];
+const uint8_t *model = ff_celt_coarse_energy_dist[f->size][0];
+
+/* intra frame */
+if (opus_rc_tell(rc) + 3 <= f->framebits && ff_opus_rc_dec_log(rc, 3)) {
+alpha = 0.0f;
+beta  = 1.0f - (4915.0f/32768.0f);
 model = ff_celt_coarse_energy_dist[f->size][1];
-} else {
-alpha = ff_celt_alpha_coef[f->size];
-beta  = 1.0f - ff_celt_beta_coef[f->size];
-model = ff_celt_coarse_energy_dist[f->size][0];
 }
 
 for (i = 0; i < CELT_MAX_BANDS; i++) {
diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
index c54df8c060..8f2da4a7ba 100644
--- a/libavcodec/opusenc.c
+++ b/libavcodec/opusenc.c
@@ -644,10 +644,10 @@ static void exp_quant_coarse(OpusRangeCoder *rc, 
CeltFrame *f,
 
 if (intra) {
 alpha = 0.0f;
-beta  = 1.0f - 4915.0f/32768.0f;
+beta  = 1.0f - (4915.0f/32768.0f);
 } else {
 alpha = ff_celt_alpha_coef[f->size];
-beta  = 1.0f - ff_celt_beta_coef[f->size];
+beta  = ff_celt_beta_coef[f->size];
 }
 
 for (i = f->start_band; i < f->end_band; i++) {
diff --git a/libavcodec/opustab.c b/libavcodec/opustab.c
index b31705297e..fb340e07e8 100644
--- a/libavcodec/opustab.c
+++ b/libavcodec/opustab.c
@@ -796,8 +796,8 @@ const float ff_celt_alpha_coef[] = {
 29440.0f/32768.0f,26112.0f/32768.0f,21248.0f/32768.0f,
16384.0f/32768.0f
 };
 
-const float ff_celt_beta_coef[] = { /* TODO: precompute 1 minus this if the 
code ends up neater */
-30147.0f/32768.0f,22282.0f/32768.0f,12124.0f/32768.0f, 
6554.0f/32768.0f
+const float ff_celt_beta_coef[] = {
+1.0f - (30147.0f/32768.0f), 1.0f - (22282.0f/32768.0f), 1.0f - 
(12124.0f/32768.0f), 1.0f - (6554.0f/32768.0f),
 };
 
 const uint8_t ff_celt_coarse_energy_dist[4][2][42] = {

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


[FFmpeg-cvslog] avcodec/aacdec_template (fixed point): Check gain in decode_cce() to avoid undefined shifts later

2017-07-18 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sat 
Jul 15 22:22:52 2017 +0200| [2886142e0c3b5f4304c6e2a2bd282770a8a47f93] | 
committer: Michael Niedermayer

avcodec/aacdec_template (fixed point): Check gain in decode_cce() to avoid 
undefined shifts later

Fixes: runtime error: shift exponent 47 is too large for 32-bit type 'int'
Fixes: 2581/clusterfuzz-testcase-minimized-4681474395602944

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

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

 libavcodec/aacdec_template.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index c60a6ca096..90cc143781 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -2199,6 +2199,10 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, 
ChannelElement *che)
 cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb);
 gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0;
 gain_cache = GET_GAIN(scale, gain);
+#if USE_FIXED
+if ((abs(gain_cache)-1024) >> 3 > 30)
+return AVERROR(ERANGE);
+#endif
 }
 if (coup->coupling_point == AFTER_IMDCT) {
 coup->gain[c][0] = gain_cache;
@@ -2216,6 +2220,10 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, 
ChannelElement *che)
 t >>= 1;
 }
 gain_cache = GET_GAIN(scale, t) * s;
+#if USE_FIXED
+if ((abs(gain_cache)-1024) >> 3 > 30)
+return AVERROR(ERANGE);
+#endif
 }
 }
 coup->gain[c][idx] = gain_cache;

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


[FFmpeg-cvslog] avcodec/htmlsubtitles: Be a bit more picky on syntax

2017-07-18 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sun 
Jul  2 00:09:42 2017 +0200| [c61715e2c505c15a5cfc9eab18b4311a6504055a] | 
committer: Michael Niedermayer

avcodec/htmlsubtitles: Be a bit more picky on syntax

This reduces the number of strstr() calls per byte
This diasalows empty tags like '< >' as well as '<' in tags like ''

Fixes timeout
Fixes: 1817/clusterfuzz-testcase-minimized-5104230530547712

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 

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

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

diff --git a/libavcodec/htmlsubtitles.c b/libavcodec/htmlsubtitles.c
index 9575464063..e6bac713c1 100644
--- a/libavcodec/htmlsubtitles.c
+++ b/libavcodec/htmlsubtitles.c
@@ -110,13 +110,13 @@ int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, 
const char *in)
 case '<':
 tag_close = in[1] == '/';
 len = 0;
-if (sscanf(in+tag_close+1, "%127[^>]>%n", buffer, &len) >= 1 && 
len > 0) {
+if (sscanf(in+tag_close+1, "%127[^<>]>%n", buffer, &len) >= 1 && 
len > 0) {
 const char *tagname = buffer;
 while (*tagname == ' ')
 tagname++;
 if ((param = strchr(tagname, ' ')))
 *param++ = 0;
-if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||
+if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack) && *tagname) ||
 ( tag_close && sptr > 0 && 
!av_strcasecmp(stack[sptr-1].tag, tagname))) {
 int i, j, unknown = 0;
 in += len + tag_close;

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


[FFmpeg-cvslog] lavc/vaapi_encode_h265: Remove duplicate slice_segment_address.

2017-07-18 Thread Jun Zhao
ffmpeg | branch: master | Jun Zhao  | Tue Jul 18 00:01:09 
2017 -0400| [5b8a708492f84ab49bcf9f694c50ac87cbdcc21b] | committer: Mark 
Thompson

lavc/vaapi_encode_h265: Remove duplicate slice_segment_address.

the VAEncSliceParameterBufferHEVC in libva have support this field,
so remove the duplicate field in VAAPIEncodeH265MiscSliceParams.

Signed-off-by: Jun Zhao 
Signed-off-by: Mark Thompson 

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

 libavcodec/vaapi_encode_h265.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 1d648a6d87..cf6b9388d1 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -149,7 +149,6 @@ typedef struct VAAPIEncodeH265MiscSequenceParams {
 typedef struct VAAPIEncodeH265MiscSliceParams {
 // Slice segments.
 char first_slice_segment_in_pic_flag;
-unsigned int slice_segment_address;
 
 // Short-term reference picture sets.
 char short_term_ref_pic_set_sps_flag;
@@ -586,7 +585,7 @@ static void 
vaapi_encode_h265_write_slice_header2(PutBitContext *pbc,
 if (vpic->pic_fields.bits.dependent_slice_segments_enabled_flag)
 u(1, vslice_field(dependent_slice_segment_flag));
 u(av_log2((priv->ctu_width * priv->ctu_height) - 1) + 1,
-  mslice_var(slice_segment_address));
+  vslice_var(slice_segment_address));
 }
 if (!vslice->slice_fields.bits.dependent_slice_segment_flag) {
 for (i = 0; i < mseq->num_extra_slice_header_bits; i++)

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


[FFmpeg-cvslog] pixdesc: Improve scoring for opaque/unknown pixel formats

2017-07-18 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Thu Jul  6 22:50:35 
2017 +0100| [8a442d7a8a687a469ca502a18a0c68f5302b15e0] | committer: Mark 
Thompson

pixdesc: Improve scoring for opaque/unknown pixel formats

Hardware pixel formats do not tell you anything about their actual
contents, but should still score higher than formats with completely
unknown properties, which in turn should score higher than invalid
formats.

Do not return an AVERROR code as a score.

Fixes a hang in libavfilter where format negotiation gets stuck in a
loop because AV_PIX_FMT_NONE scores more highly than all other
possibilities.

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

 libavutil/pixdesc.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 46a7eff06d..1983ce9ef5 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -2511,8 +2511,16 @@ static int get_pix_fmt_score(enum AVPixelFormat 
dst_pix_fmt,
 int ret, loss, i, nb_components;
 int score = INT_MAX - 1;
 
-if (dst_pix_fmt >= AV_PIX_FMT_NB || dst_pix_fmt <= AV_PIX_FMT_NONE)
-return ~0;
+if (!src_desc || !dst_desc)
+return -4;
+
+if ((src_desc->flags & AV_PIX_FMT_FLAG_HWACCEL) ||
+(dst_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
+if (dst_pix_fmt == src_pix_fmt)
+return -1;
+else
+return -2;
+}
 
 /* compute loss */
 *lossp = loss = 0;
@@ -2521,9 +2529,9 @@ static int get_pix_fmt_score(enum AVPixelFormat 
dst_pix_fmt,
 return INT_MAX;
 
 if ((ret = get_pix_fmt_depth(&src_min_depth, &src_max_depth, src_pix_fmt)) 
< 0)
-return ret;
+return -3;
 if ((ret = get_pix_fmt_depth(&dst_min_depth, &dst_max_depth, dst_pix_fmt)) 
< 0)
-return ret;
+return -3;
 
 src_color = get_color_type(src_desc);
 dst_color = get_color_type(dst_desc);

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


[FFmpeg-cvslog] pixdesc: Add a test for av_find_best_pix_fmt_of_2()

2017-07-18 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Thu Jul  6 22:50:40 
2017 +0100| [3192821237f6dbf2190264a6efab935280559373] | committer: Mark 
Thompson

pixdesc: Add a test for av_find_best_pix_fmt_of_2()

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

 libavutil/Makefile|   1 +
 libavutil/tests/pixfmt_best.c | 125 ++
 tests/fate/libavutil.mak  |   4 ++
 tests/ref/fate/pixfmt_best|   1 +
 4 files changed, 131 insertions(+)

diff --git a/libavutil/Makefile b/libavutil/Makefile
index b4464b0d76..b2662c843e 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -218,6 +218,7 @@ TESTPROGS = adler32 
\
 parseutils  \
 pixdesc \
 pixelutils  \
+pixfmt_best \
 random_seed \
 rational\
 ripemd  \
diff --git a/libavutil/tests/pixfmt_best.c b/libavutil/tests/pixfmt_best.c
new file mode 100644
index 00..a617633e9b
--- /dev/null
+++ b/libavutil/tests/pixfmt_best.c
@@ -0,0 +1,125 @@
+/*
+ * 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 "libavutil/pixdesc.c"
+
+static const enum AVPixelFormat pixfmt_list[] = {
+AV_PIX_FMT_MONOWHITE,
+AV_PIX_FMT_GRAY8,
+AV_PIX_FMT_GRAY10,
+AV_PIX_FMT_GRAY16,
+AV_PIX_FMT_YUV420P,
+AV_PIX_FMT_YUV420P10,
+AV_PIX_FMT_YUV420P16,
+AV_PIX_FMT_YUV422P,
+AV_PIX_FMT_YUV422P10,
+AV_PIX_FMT_YUV422P16,
+AV_PIX_FMT_YUV444P,
+AV_PIX_FMT_YUV444P10,
+AV_PIX_FMT_YUV444P16,
+AV_PIX_FMT_RGB565,
+AV_PIX_FMT_RGB24,
+AV_PIX_FMT_RGB48,
+AV_PIX_FMT_VDPAU,
+AV_PIX_FMT_VAAPI,
+};
+
+static enum AVPixelFormat find_best(enum AVPixelFormat pixfmt)
+{
+enum AVPixelFormat best = AV_PIX_FMT_NONE;
+int i;
+for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
+best = av_find_best_pix_fmt_of_2(best, pixfmt_list[i],
+ pixfmt, 0, NULL);
+return best;
+}
+
+int main(void)
+{
+enum AVPixelFormat output;
+int i, pass = 0, fail = 0;
+
+#define TEST(input, expected) do {  \
+output = find_best(input);  \
+if (output != expected) {   \
+printf("Matching %s: got %s, expected %s\n",\
+   av_get_pix_fmt_name(input),  \
+   av_get_pix_fmt_name(output), \
+   av_get_pix_fmt_name(expected));  \
+++fail; \
+} else  \
+++pass; \
+} while (0)
+
+// Same formats.
+for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
+TEST(pixfmt_list[i], pixfmt_list[i]);
+
+// Formats containing the same data in different layouts.
+TEST(AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_MONOWHITE);
+TEST(AV_PIX_FMT_NV12,  AV_PIX_FMT_YUV420P);
+TEST(AV_PIX_FMT_P010,  AV_PIX_FMT_YUV420P10);
+TEST(AV_PIX_FMT_P016,  AV_PIX_FMT_YUV420P16);
+TEST(AV_PIX_FMT_NV16,  AV_PIX_FMT_YUV422P);
+TEST(AV_PIX_FMT_YUYV422,   AV_PIX_FMT_YUV422P);
+TEST(AV_PIX_FMT_UYVY422,   AV_PIX_FMT_YUV422P);
+TEST(AV_PIX_FMT_BGR565,AV_PIX_FMT_RGB565);
+TEST(AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24);
+TEST(AV_PIX_FMT_GBRP,  AV_PIX_FMT_RGB24);
+TEST(AV_PIX_FMT_0RGB,  AV_PIX_FMT_RGB24);
+TEST(AV_PIX_FMT_GBRP16,AV_PIX_FMT_RGB48);
+
+// Formats additionally containing alpha (here ignored).
+TEST(AV_PIX_FMT_YA8,   AV_PIX_FMT_GRAY8);
+TEST(AV_PIX_FMT_YA16,  AV_PIX_FMT_GRAY16);
+TEST(AV_PIX_FMT_YUVA420P,  AV_PIX_FMT_YUV420P);
+TEST(AV_PIX_FMT_YUVA422P,  AV_P

[FFmpeg-cvslog] doc: Fix names of VAAPI encoders

2017-07-18 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Tue Jul 18 23:36:06 
2017 +0100| [e6b4fb95d76bd9794aa6ac9e64791638b6c2baa8] | committer: Mark 
Thompson

doc: Fix names of VAAPI encoders

They were all reversed (oops).

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

 doc/encoders.texi | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 9f03c0c608..690cca83dc 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2570,7 +2570,7 @@ The following standard libavcodec options are used:
 
 @table @option
 
-@item vaapi_h264
+@item h264_vaapi
 @option{profile} sets the value of @emph{profile_idc} and the 
@emph{constraint_set*_flag}s.
 @option{level} sets the value of @emph{level_idc}.
 
@@ -2582,20 +2582,20 @@ systems implement all levels).
 Use low-power encoding mode.
 @end table
 
-@item vaapi_hevc
+@item hevc_vaapi
 @option{profile} and @option{level} set the values of
 @emph{general_profile_idc} and @emph{general_level_idc} respectively.
 
-@item vaapi_mjpeg
+@item mjpeg_vaapi
 Always encodes using the standard quantisation and huffman tables -
 @option{global_quality} scales the standard quantisation table (range 1-100).
 
-@item vaapi_mpeg2
+@item mpeg2_vaapi
 @option{profile} and @option{level} set the value of 
@emph{profile_and_level_indication}.
 
 No rate control is supported.
 
-@item vaapi_vp8
+@item vp8_vaapi
 B-frames are not supported.
 
 @option{global_quality} sets the @emph{q_idx} used for non-key frames (range 
0-127).
@@ -2606,7 +2606,7 @@ B-frames are not supported.
 Manually set the loop filter parameters.
 @end table
 
-@item vaapi_vp9
+@item vp9_vaapi
 @option{global_quality} sets the @emph{q_idx} used for P-frames (range 0-255).
 
 @table @option

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


[FFmpeg-cvslog] lavc/codec_desc: Mark some uncompressed codecs as lossless.

2017-07-18 Thread Carl Eugen Hoyos
ffmpeg | branch: master | Carl Eugen Hoyos  | Wed Jul 19 
01:55:21 2017 +0200| [5c7e7ac6d4504364b2f08a05cc983ced76bb5c51] | committer: 
Carl Eugen Hoyos

lavc/codec_desc: Mark some uncompressed codecs as lossless.

Fixes ticket #6526.

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

 libavcodec/codec_desc.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index cf1246e431..caff7e665d 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1115,7 +1115,7 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "y41p",
 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed YUV 4:1:1 12-bit"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_ESCAPE130,
@@ -1129,56 +1129,56 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "avrp",
 .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_012V,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "012v",
 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_AVUI,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "avui",
 .long_name = NULL_IF_CONFIG_SMALL("Avid Meridien Uncompressed"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_AYUV,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "ayuv",
 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_TARGA_Y216,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "targa_y216",
 .long_name = NULL_IF_CONFIG_SMALL("Pinnacle TARGA CineWave YUV16"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_V308,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "v308",
 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:4:4"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_V408,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "v408",
 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_YUV4,
 .type  = AVMEDIA_TYPE_VIDEO,
 .name  = "yuv4",
 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"),
-.props = AV_CODEC_PROP_INTRA_ONLY,
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
 },
 {
 .id= AV_CODEC_ID_AVRN,

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


[FFmpeg-cvslog] avcodec/dca: move some enumeration typedefs into headers

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:31 2017 
+0300| [f6b86b62f785a67a356c87f5ea483a1cbe338191] | committer: James Almer

avcodec/dca: move some enumeration typedefs into headers

These values will be used by the parser. Prefix them with DCA_
appropriately.

Signed-off-by: James Almer 

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

 libavcodec/dca_core.c | 68 +++
 libavcodec/dca_core.h | 28 +
 libavcodec/dca_lbr.c  |  9 ++-
 libavcodec/dca_lbr.h  |  5 
 4 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 36040f6f9d..16210b89f8 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -35,35 +35,7 @@ enum HeaderType {
 HEADER_XXCH
 };
 
-enum AudioMode {
-AMODE_MONO, // Mode 0: A (mono)
-AMODE_MONO_DUAL,// Mode 1: A + B (dual mono)
-AMODE_STEREO,   // Mode 2: L + R (stereo)
-AMODE_STEREO_SUMDIFF,   // Mode 3: (L+R) + (L-R) (sum-diff)
-AMODE_STEREO_TOTAL, // Mode 4: LT + RT (left and right total)
-AMODE_3F,   // Mode 5: C + L + R
-AMODE_2F1R, // Mode 6: L + R + S
-AMODE_3F1R, // Mode 7: C + L + R + S
-AMODE_2F2R, // Mode 8: L + R + SL + SR
-AMODE_3F2R, // Mode 9: C + L + R + SL + SR
-
-AMODE_COUNT
-};
-
-enum ExtAudioType {
-EXT_AUDIO_XCH   = 0,
-EXT_AUDIO_X96   = 2,
-EXT_AUDIO_XXCH  = 6
-};
-
-enum LFEFlag {
-LFE_FLAG_NONE,
-LFE_FLAG_128,
-LFE_FLAG_64,
-LFE_FLAG_INVALID
-};
-
-static const int8_t prm_ch_to_spkr_map[AMODE_COUNT][5] = {
+static const int8_t prm_ch_to_spkr_map[DCA_AMODE_COUNT][5] = {
 { DCA_SPEAKER_C,-1, -1, -1,
 -1 },
 { DCA_SPEAKER_L, DCA_SPEAKER_R, -1, -1,
 -1 },
 { DCA_SPEAKER_L, DCA_SPEAKER_R, -1, -1,
 -1 },
@@ -76,7 +48,7 @@ static const int8_t prm_ch_to_spkr_map[AMODE_COUNT][5] = {
 { DCA_SPEAKER_C, DCA_SPEAKER_L, DCA_SPEAKER_R,  DCA_SPEAKER_Ls, 
DCA_SPEAKER_Rs }
 };
 
-static const uint8_t audio_mode_ch_mask[AMODE_COUNT] = {
+static const uint8_t audio_mode_ch_mask[DCA_AMODE_COUNT] = {
 DCA_SPEAKER_LAYOUT_MONO,
 DCA_SPEAKER_LAYOUT_STEREO,
 DCA_SPEAKER_LAYOUT_STEREO,
@@ -139,7 +111,7 @@ static int parse_frame_header(DCACoreDecoder *s)
 
 // Audio channel arrangement
 s->audio_mode = get_bits(&s->gb, 6);
-if (s->audio_mode >= AMODE_COUNT) {
+if (s->audio_mode >= DCA_AMODE_COUNT) {
 av_log(s->avctx, AV_LOG_ERROR, "Unsupported audio channel arrangement 
(%d)\n", s->audio_mode);
 return AVERROR_PATCHWELCOME;
 }
@@ -180,7 +152,7 @@ static int parse_frame_header(DCACoreDecoder *s)
 
 // Low frequency effects flag
 s->lfe_present = get_bits(&s->gb, 2);
-if (s->lfe_present == LFE_FLAG_INVALID) {
+if (s->lfe_present == DCA_LFE_FLAG_INVALID) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid low frequency effects flag\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1783,7 +1755,7 @@ static int parse_optional_info(DCACoreDecoder *s)
 // must be done backwards from the end of core frame to work around
 // sync word aliasing issues.
 switch (s->ext_audio_type) {
-case EXT_AUDIO_XCH:
+case DCA_EXT_AUDIO_XCH:
 if (dca->request_channel_layout)
 break;
 
@@ -1813,7 +1785,7 @@ static int parse_optional_info(DCACoreDecoder *s)
 }
 break;
 
-case EXT_AUDIO_X96:
+case DCA_EXT_AUDIO_X96:
 // The distance between X96 sync word and end of the core frame
 // must be equal to X96 frame size. Minimum X96 frame size is 96
 // bytes.
@@ -1836,7 +1808,7 @@ static int parse_optional_info(DCACoreDecoder *s)
 }
 break;
 
-case EXT_AUDIO_XXCH:
+case DCA_EXT_AUDIO_XXCH:
 if (dca->request_channel_layout)
 break;
 
@@ -2102,7 +2074,7 @@ int ff_dca_core_filter_fixed(DCACoreDecoder *s, int 
x96_synth)
 int nlfesamples = s->npcmblocks >> 1;
 
 // Check LFF
-if (s->lfe_present == LFE_FLAG_128) {
+if (s->lfe_present == DCA_LFE_FLAG_128) {
 av_log(s->avctx, AV_LOG_ERROR, "Fixed point mode doesn't support 
LFF=1\n");
 return AVERROR(EINVAL);
 }
@@ -2152,7 +2124,7 @@ static int filter_frame_fixed(DCACoreDecoder *s, AVFrame 
*frame)
 
 // Undo embedded XCH downmix
 if (s->es_format && (s->ext_audio_mask & DCA_CSS_XCH)
-&& s->audio_mode >= AMODE_2F2R) {
+&& s->audio_mode >= DCA_AMODE_2F2R) {
 s->dcadsp->dmix_sub_xch(s->output_samples[DCA_SPEAKER_Ls],
 s->output_samples[DCA_SPEAKER_Rs],

[FFmpeg-cvslog] avcodec/dca: move bits per sample array to dca.c

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:32 2017 
+0300| [9e37cc11012f23e39b63032b5daac03621340a4f] | committer: James Almer

avcodec/dca: move bits per sample array to dca.c

It will be used by the parser. This change avoids unwanted parser
dependency on dcadata.

Signed-off-by: James Almer 

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

 libavcodec/dca.c | 4 
 libavcodec/dca.h | 2 ++
 libavcodec/dcadata.c | 4 
 libavcodec/dcadata.h | 2 --
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index 58f340e6da..fb796191d6 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -45,6 +45,10 @@ const uint8_t ff_dca_freq_ranges[16] = {
 0, 1, 2, 3, 4, 1, 2, 3, 4, 4, 0, 1, 2, 3, 4, 4
 };
 
+const uint8_t ff_dca_bits_per_sample[8] = {
+16, 16, 20, 20, 0, 24, 24, 0
+};
+
 int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t 
*dst,
  int max_size)
 {
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index bd96bc9ee3..1d10de4b94 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -156,6 +156,8 @@ extern av_export const uint32_t avpriv_dca_sample_rates[16];
 
 extern const uint32_t ff_dca_sampling_freqs[16];
 extern const uint8_t ff_dca_freq_ranges[16];
+extern const uint8_t ff_dca_bits_per_sample[8];
+
 
 /**
  * Convert bitstream to one representation based on sync marker
diff --git a/libavcodec/dcadata.c b/libavcodec/dcadata.c
index eaef01875a..1b646a7aa6 100644
--- a/libavcodec/dcadata.c
+++ b/libavcodec/dcadata.c
@@ -42,10 +42,6 @@ const uint8_t ff_dca_channels[16] = {
 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8
 };
 
-const uint8_t ff_dca_bits_per_sample[8] = {
-16, 16, 20, 20, 0, 24, 24, 0
-};
-
 const uint8_t ff_dca_dmix_primary_nch[8] = {
 1, 2, 2, 3, 3, 4, 4, 0
 };
diff --git a/libavcodec/dcadata.h b/libavcodec/dcadata.h
index 9dd6eba7f1..5aa85b3414 100644
--- a/libavcodec/dcadata.h
+++ b/libavcodec/dcadata.h
@@ -32,8 +32,6 @@ extern const uint32_t ff_dca_bit_rates[32];
 
 extern const uint8_t ff_dca_channels[16];
 
-extern const uint8_t ff_dca_bits_per_sample[8];
-
 extern const uint8_t ff_dca_dmix_primary_nch[8];
 
 extern const uint8_t ff_dca_quant_index_sel_nbits[DCA_CODE_BOOKS];

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


[FFmpeg-cvslog] avcodec/dca_parser: switch to common frame header parsing function

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:35 2017 
+0300| [e54b9be1ffd669c76458324206935c8927a7c705] | committer: James Almer

avcodec/dca_parser: switch to common frame header parsing function

Signed-off-by: James Almer 

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

 libavcodec/dca_parser.c | 26 +++---
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index e5bea3347c..6107358773 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -192,10 +192,11 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 int buf_size, int *duration, int *sample_rate)
 {
 GetBitContext gb;
-uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
-int ret, sample_blocks;
+DCACoreFrameHeader h;
+uint8_t hdr[DCA_CORE_FRAME_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE] = { 
0 };
+int ret;
 
-if (buf_size < 12)
+if (buf_size < DCA_CORE_FRAME_HEADER_SIZE)
 return AVERROR_INVALIDDATA;
 
 if (AV_RB32(buf) == DCA_SYNCWORD_SUBSTREAM) {
@@ -255,21 +256,16 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 return AVERROR_INVALIDDATA;
 }
 
-if ((ret = avpriv_dca_convert_bitstream(buf, 12, hdr, 12)) < 0)
+if ((ret = avpriv_dca_convert_bitstream(buf, DCA_CORE_FRAME_HEADER_SIZE,
+hdr, DCA_CORE_FRAME_HEADER_SIZE)) 
< 0)
 return ret;
-
-init_get_bits(&gb, hdr, 96);
-
-skip_bits_long(&gb, 39);
-sample_blocks = get_bits(&gb, 7) + 1;
-if (sample_blocks < 8)
+if ((ret = init_get_bits8(&gb, hdr, ret)) < 0)
+return ret;
+if (avpriv_dca_parse_core_frame_header(&gb, &h) < 0)
 return AVERROR_INVALIDDATA;
-*duration = 256 * (sample_blocks / 8);
 
-skip_bits(&gb, 20);
-*sample_rate = avpriv_dca_sample_rates[get_bits(&gb, 4)];
-if (*sample_rate == 0)
-return AVERROR_INVALIDDATA;
+*duration = 256 * (h.npcmblocks / 8);
+*sample_rate = avpriv_dca_sample_rates[h.sr_code];
 
 return 0;
 }

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


[FFmpeg-cvslog] avcodec: add avpriv_dca_parse_core_frame_header()

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:33 2017 
+0300| [2123ddb4251bf39bde8b38a1307a0f6154d260e6] | committer: James Almer

avcodec: add avpriv_dca_parse_core_frame_header()

There are 3 different places where DCA core frame header is parsed:
decoder, parser and demuxer. Each one uses ad-hoc code. Add common core
frame header parsing function that will be used in all places.

Signed-off-by: James Almer 

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

 libavcodec/dca.c | 60 
 libavcodec/dca.h | 49 ++
 libavcodec/version.h |  4 ++--
 3 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index fb796191d6..39f8f3d81c 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -28,7 +28,9 @@
 #include "libavutil/error.h"
 
 #include "dca.h"
+#include "dca_core.h"
 #include "dca_syncwords.h"
+#include "get_bits.h"
 #include "put_bits.h"
 
 const uint32_t avpriv_dca_sample_rates[16] = {
@@ -85,3 +87,61 @@ int avpriv_dca_convert_bitstream(const uint8_t *src, int 
src_size, uint8_t *dst,
 return AVERROR_INVALIDDATA;
 }
 }
+
+int avpriv_dca_parse_core_frame_header(GetBitContext *gb, DCACoreFrameHeader 
*h)
+{
+if (get_bits_long(gb, 32) != DCA_SYNCWORD_CORE_BE)
+return DCA_PARSE_ERROR_SYNC_WORD;
+
+h->normal_frame = get_bits1(gb);
+h->deficit_samples = get_bits(gb, 5) + 1;
+if (h->deficit_samples != DCA_PCMBLOCK_SAMPLES)
+return DCA_PARSE_ERROR_DEFICIT_SAMPLES;
+
+h->crc_present = get_bits1(gb);
+h->npcmblocks = get_bits(gb, 7) + 1;
+if (h->npcmblocks & (DCA_SUBBAND_SAMPLES - 1))
+return DCA_PARSE_ERROR_PCM_BLOCKS;
+
+h->frame_size = get_bits(gb, 14) + 1;
+if (h->frame_size < 96)
+return DCA_PARSE_ERROR_FRAME_SIZE;
+
+h->audio_mode = get_bits(gb, 6);
+if (h->audio_mode >= DCA_AMODE_COUNT)
+return DCA_PARSE_ERROR_AMODE;
+
+h->sr_code = get_bits(gb, 4);
+if (!avpriv_dca_sample_rates[h->sr_code])
+return DCA_PARSE_ERROR_SAMPLE_RATE;
+
+h->br_code = get_bits(gb, 5);
+if (get_bits1(gb))
+return DCA_PARSE_ERROR_RESERVED_BIT;
+
+h->drc_present = get_bits1(gb);
+h->ts_present = get_bits1(gb);
+h->aux_present = get_bits1(gb);
+h->hdcd_master = get_bits1(gb);
+h->ext_audio_type = get_bits(gb, 3);
+h->ext_audio_present = get_bits1(gb);
+h->sync_ssf = get_bits1(gb);
+h->lfe_present = get_bits(gb, 2);
+if (h->lfe_present == DCA_LFE_FLAG_INVALID)
+return DCA_PARSE_ERROR_LFE_FLAG;
+
+h->predictor_history = get_bits1(gb);
+if (h->crc_present)
+skip_bits(gb, 16);
+h->filter_perfect = get_bits1(gb);
+h->encoder_rev = get_bits(gb, 4);
+h->copy_hist = get_bits(gb, 2);
+h->pcmr_code = get_bits(gb, 3);
+if (!ff_dca_bits_per_sample[h->pcmr_code])
+return DCA_PARSE_ERROR_PCM_RES;
+
+h->sumdiff_front = get_bits1(gb);
+h->sumdiff_surround = get_bits1(gb);
+h->dn_code = get_bits(gb, 4);
+return 0;
+}
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index 1d10de4b94..cf6204e554 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -32,6 +32,49 @@
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 
+#include "get_bits.h"
+
+#define DCA_CORE_FRAME_HEADER_SIZE  18
+
+enum DCAParseError {
+DCA_PARSE_ERROR_SYNC_WORD   = -1,
+DCA_PARSE_ERROR_DEFICIT_SAMPLES = -2,
+DCA_PARSE_ERROR_PCM_BLOCKS  = -3,
+DCA_PARSE_ERROR_FRAME_SIZE  = -4,
+DCA_PARSE_ERROR_AMODE   = -5,
+DCA_PARSE_ERROR_SAMPLE_RATE = -6,
+DCA_PARSE_ERROR_RESERVED_BIT= -7,
+DCA_PARSE_ERROR_LFE_FLAG= -8,
+DCA_PARSE_ERROR_PCM_RES = -9
+};
+
+typedef struct DCACoreFrameHeader {
+uint8_t normal_frame;   ///< Frame type
+uint8_t deficit_samples;///< Deficit sample count
+uint8_t crc_present;///< CRC present flag
+uint8_t npcmblocks; ///< Number of PCM sample blocks
+uint16_tframe_size; ///< Primary frame byte size
+uint8_t audio_mode; ///< Audio channel arrangement
+uint8_t sr_code;///< Core audio sampling frequency
+uint8_t br_code;///< Transmission bit rate
+uint8_t drc_present;///< Embedded dynamic range flag
+uint8_t ts_present; ///< Embedded time stamp flag
+uint8_t aux_present;///< Auxiliary data flag
+uint8_t hdcd_master;///< HDCD mastering flag
+uint8_t ext_audio_type; ///< Extension audio descriptor flag
+uint8_t ext_audio_present;  ///< Extended coding flag
+uint8_t sync_ssf;   ///< Audio sync word insertion flag
+uint8_t lfe_present;///< Low frequency effects flag
+uint8_t predictor_history;  ///<

[FFmpeg-cvslog] avcodec/dca_core: switch to common frame header parsing function

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:34 2017 
+0300| [33fc6c17a6e76ec2894e656cfeba5bcba9498778] | committer: James Almer

avcodec/dca_core: switch to common frame header parsing function

Signed-off-by: James Almer 

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

 libavcodec/dca_core.c | 149 +-
 1 file changed, 51 insertions(+), 98 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 16210b89f8..090191dfa9 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -81,114 +81,68 @@ static void get_array(GetBitContext *s, int32_t *array, 
int size, int n)
 // 5.3.1 - Bit stream header
 static int parse_frame_header(DCACoreDecoder *s)
 {
-int normal_frame, pcmr_index;
+DCACoreFrameHeader h = { 0 };
+int err = avpriv_dca_parse_core_frame_header(&s->gb, &h);
 
-// Frame type
-normal_frame = get_bits1(&s->gb);
+if (err < 0) {
+switch (err) {
+case DCA_PARSE_ERROR_DEFICIT_SAMPLES:
+av_log(s->avctx, AV_LOG_ERROR, "Deficit samples are not 
supported\n");
+return h.normal_frame ? AVERROR_INVALIDDATA : AVERROR_PATCHWELCOME;
 
-// Deficit sample count
-if (get_bits(&s->gb, 5) != DCA_PCMBLOCK_SAMPLES - 1) {
-av_log(s->avctx, AV_LOG_ERROR, "Deficit samples are not supported\n");
-return normal_frame ? AVERROR_INVALIDDATA : AVERROR_PATCHWELCOME;
-}
-
-// CRC present flag
-s->crc_present = get_bits1(&s->gb);
-
-// Number of PCM sample blocks
-s->npcmblocks = get_bits(&s->gb, 7) + 1;
-if (s->npcmblocks & (DCA_SUBBAND_SAMPLES - 1)) {
-av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of PCM sample 
blocks (%d)\n", s->npcmblocks);
-return (s->npcmblocks < 6 || normal_frame) ? AVERROR_INVALIDDATA : 
AVERROR_PATCHWELCOME;
-}
-
-// Primary frame byte size
-s->frame_size = get_bits(&s->gb, 14) + 1;
-if (s->frame_size < 96) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid core frame size (%d bytes)\n", 
s->frame_size);
-return AVERROR_INVALIDDATA;
-}
-
-// Audio channel arrangement
-s->audio_mode = get_bits(&s->gb, 6);
-if (s->audio_mode >= DCA_AMODE_COUNT) {
-av_log(s->avctx, AV_LOG_ERROR, "Unsupported audio channel arrangement 
(%d)\n", s->audio_mode);
-return AVERROR_PATCHWELCOME;
-}
-
-// Core audio sampling frequency
-s->sample_rate = avpriv_dca_sample_rates[get_bits(&s->gb, 4)];
-if (!s->sample_rate) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid core audio sampling 
frequency\n");
-return AVERROR_INVALIDDATA;
-}
-
-// Transmission bit rate
-s->bit_rate = ff_dca_bit_rates[get_bits(&s->gb, 5)];
-
-// Reserved field
-skip_bits1(&s->gb);
-
-// Embedded dynamic range flag
-s->drc_present = get_bits1(&s->gb);
-
-// Embedded time stamp flag
-s->ts_present = get_bits1(&s->gb);
-
-// Auxiliary data flag
-s->aux_present = get_bits1(&s->gb);
-
-// HDCD mastering flag
-skip_bits1(&s->gb);
+case DCA_PARSE_ERROR_PCM_BLOCKS:
+av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of PCM sample 
blocks (%d)\n", h.npcmblocks);
+return (h.npcmblocks < 6 || h.normal_frame) ? AVERROR_INVALIDDATA 
: AVERROR_PATCHWELCOME;
 
-// Extension audio descriptor flag
-s->ext_audio_type = get_bits(&s->gb, 3);
-
-// Extended coding flag
-s->ext_audio_present = get_bits1(&s->gb);
-
-// Audio sync word insertion flag
-s->sync_ssf = get_bits1(&s->gb);
-
-// Low frequency effects flag
-s->lfe_present = get_bits(&s->gb, 2);
-if (s->lfe_present == DCA_LFE_FLAG_INVALID) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid low frequency effects flag\n");
-return AVERROR_INVALIDDATA;
-}
+case DCA_PARSE_ERROR_FRAME_SIZE:
+av_log(s->avctx, AV_LOG_ERROR, "Invalid core frame size (%d 
bytes)\n", h.frame_size);
+return AVERROR_INVALIDDATA;
 
-// Predictor history flag switch
-s->predictor_history = get_bits1(&s->gb);
+case DCA_PARSE_ERROR_AMODE:
+av_log(s->avctx, AV_LOG_ERROR, "Unsupported audio channel 
arrangement (%d)\n", h.audio_mode);
+return AVERROR_PATCHWELCOME;
 
-// Header CRC check bytes
-if (s->crc_present)
-skip_bits(&s->gb, 16);
+case DCA_PARSE_ERROR_SAMPLE_RATE:
+av_log(s->avctx, AV_LOG_ERROR, "Invalid core audio sampling 
frequency\n");
+return AVERROR_INVALIDDATA;
 
-// Multirate interpolator switch
-s->filter_perfect = get_bits1(&s->gb);
+case DCA_PARSE_ERROR_RESERVED_BIT:
+av_log(s->avctx, AV_LOG_ERROR, "Reserved bit set\n");
+return AVERROR_INVALIDDATA;
 
-// Encoder software revision
-skip_bits(&s->gb, 4);
+case DCA_PARSE_ERROR_LFE_FLAG:
+av_log(s->avctx, AV_LOG_ERROR, "Invali

[FFmpeg-cvslog] avcodec/dca_parser: export profile information

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:37 2017 
+0300| [4b6c212e859f49360f50c4d67b999769cc7cc2c6] | committer: James Almer

avcodec/dca_parser: export profile information

Permits applications to access DTS profile information without having to
decode a frame.

Signed-off-by: James Almer 

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

 libavcodec/dca_parser.c | 44 +++-
 1 file changed, 39 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 6107358773..390f7975f9 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -23,6 +23,7 @@
  */
 
 #include "dca.h"
+#include "dca_core.h"
 #include "dca_exss.h"
 #include "dca_syncwords.h"
 #include "get_bits.h"
@@ -189,19 +190,19 @@ static av_cold int dca_parse_init(AVCodecParserContext *s)
 }
 
 static int dca_parse_params(DCAParseContext *pc1, const uint8_t *buf,
-int buf_size, int *duration, int *sample_rate)
+int buf_size, int *duration, int *sample_rate,
+int *profile)
 {
+DCAExssAsset *asset = &pc1->exss.assets[0];
 GetBitContext gb;
 DCACoreFrameHeader h;
 uint8_t hdr[DCA_CORE_FRAME_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE] = { 
0 };
-int ret;
+int ret, frame_size;
 
 if (buf_size < DCA_CORE_FRAME_HEADER_SIZE)
 return AVERROR_INVALIDDATA;
 
 if (AV_RB32(buf) == DCA_SYNCWORD_SUBSTREAM) {
-DCAExssAsset *asset = &pc1->exss.assets[0];
-
 if ((ret = ff_dca_exss_parse(&pc1->exss, buf, buf_size)) < 0)
 return ret;
 
@@ -226,6 +227,7 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 
 *sample_rate = ff_dca_sampling_freqs[pc1->sr_code];
 *duration = 1024 << ff_dca_freq_ranges[pc1->sr_code];
+*profile = FF_PROFILE_DTS_EXPRESS;
 return 0;
 }
 
@@ -250,6 +252,7 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 
 *sample_rate = asset->max_sample_rate;
 *duration = (1 + (*sample_rate > 96000)) << nsamples_log2;
+*profile = FF_PROFILE_DTS_HD_MA;
 return 0;
 }
 
@@ -266,6 +269,37 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 
 *duration = 256 * (h.npcmblocks / 8);
 *sample_rate = avpriv_dca_sample_rates[h.sr_code];
+if (*profile != FF_PROFILE_UNKNOWN)
+return 0;
+
+*profile = FF_PROFILE_DTS;
+if (h.ext_audio_present) {
+switch (h.ext_audio_type) {
+case DCA_EXT_AUDIO_XCH:
+case DCA_EXT_AUDIO_XXCH:
+*profile = FF_PROFILE_DTS_ES;
+break;
+case DCA_EXT_AUDIO_X96:
+*profile = FF_PROFILE_DTS_96_24;
+break;
+}
+}
+
+frame_size = FFALIGN(h.frame_size, 4);
+if (buf_size - 4 < frame_size)
+return 0;
+
+buf  += frame_size;
+buf_size -= frame_size;
+if (AV_RB32(buf) != DCA_SYNCWORD_SUBSTREAM)
+return 0;
+if (ff_dca_exss_parse(&pc1->exss, buf, buf_size) < 0)
+return 0;
+
+if (asset->extension_mask & DCA_EXSS_XLL)
+*profile = FF_PROFILE_DTS_HD_MA;
+else if (asset->extension_mask & (DCA_EXSS_XBR | DCA_EXSS_XXCH | 
DCA_EXSS_X96))
+*profile = FF_PROFILE_DTS_HD_HRA;
 
 return 0;
 }
@@ -298,7 +332,7 @@ static int dca_parse(AVCodecParserContext *s, 
AVCodecContext *avctx,
 }
 
 /* read the duration and sample rate from the frame header */
-if (!dca_parse_params(pc1, buf, buf_size, &duration, &sample_rate)) {
+if (!dca_parse_params(pc1, buf, buf_size, &duration, &sample_rate, 
&avctx->profile)) {
 if (!avctx->sample_rate)
 avctx->sample_rate = sample_rate;
 s->duration = av_rescale(duration, avctx->sample_rate, sample_rate);

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


[FFmpeg-cvslog] avcodec/dca_parser: avoid use of magic values

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:38 2017 
+0300| [07a7f08b1e4b4679a3f9a60ecc45cae5078bc414] | committer: James Almer

avcodec/dca_parser: avoid use of magic values

Duration computation can be simplified because number of PCM blocks is
only allowed to be a multiple of 8.

Signed-off-by: James Almer 

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

 libavcodec/dca_parser.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 390f7975f9..7e99b16bf0 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -25,6 +25,7 @@
 #include "dca.h"
 #include "dca_core.h"
 #include "dca_exss.h"
+#include "dca_lbr.h"
 #include "dca_syncwords.h"
 #include "get_bits.h"
 #include "parser.h"
@@ -214,9 +215,9 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 return AVERROR_INVALIDDATA;
 
 switch (get_bits(&gb, 8)) {
-case 2:
+case DCA_LBR_HEADER_DECODER_INIT:
 pc1->sr_code = get_bits(&gb, 8);
-case 1:
+case DCA_LBR_HEADER_SYNC_ONLY:
 break;
 default:
 return AVERROR_INVALIDDATA;
@@ -267,7 +268,7 @@ static int dca_parse_params(DCAParseContext *pc1, const 
uint8_t *buf,
 if (avpriv_dca_parse_core_frame_header(&gb, &h) < 0)
 return AVERROR_INVALIDDATA;
 
-*duration = 256 * (h.npcmblocks / 8);
+*duration = h.npcmblocks * DCA_PCMBLOCK_SAMPLES;
 *sample_rate = avpriv_dca_sample_rates[h.sr_code];
 if (*profile != FF_PROFILE_UNKNOWN)
 return 0;

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


[FFmpeg-cvslog] avcodec/dca: avoid using bitstream reader in a non-standard way

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:40 2017 
+0300| [012620aa1b40b0642e3081871059a1be98411df4] | committer: James Almer

avcodec/dca: avoid using bitstream reader in a non-standard way

Use proper get_bits.h functions instead of directly accessing index.

Signed-off-by: James Almer 

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

 libavcodec/dca_core.c | 12 +++-
 libavcodec/dca_core.h |  1 +
 libavcodec/dca_xll.c  |  2 +-
 libavcodec/dcadec.h   |  4 ++--
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 4a7ea4e3f3..3add9f812b 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -1804,6 +1804,7 @@ int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, 
int size)
 
 if ((ret = init_get_bits8(&s->gb, data, size)) < 0)
 return ret;
+s->gb_in = s->gb;
 
 if ((ret = parse_frame_header(s)) < 0)
 return ret;
@@ -1831,7 +1832,6 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t 
*data, DCAExssAsset *asset
 {
 AVCodecContext *avctx = s->avctx;
 DCAContext *dca = avctx->priv_data;
-GetBitContext gb = s->gb;
 int exss_mask = asset ? asset->extension_mask : 0;
 int ret = 0, ext = 0;
 
@@ -1843,11 +1843,13 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t 
*data, DCAExssAsset *asset
 ret = parse_xxch_frame(s);
 ext = DCA_EXSS_XXCH;
 } else if (s->xxch_pos) {
-s->gb.index = s->xxch_pos;
+s->gb = s->gb_in;
+skip_bits_long(&s->gb, s->xxch_pos);
 ret = parse_xxch_frame(s);
 ext = DCA_CSS_XXCH;
 } else if (s->xch_pos) {
-s->gb.index = s->xch_pos;
+s->gb = s->gb_in;
+skip_bits_long(&s->gb, s->xch_pos);
 ret = parse_xch_frame(s);
 ext = DCA_CSS_XCH;
 }
@@ -1889,8 +1891,8 @@ int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t 
*data, DCAExssAsset *asset
 s->ext_audio_mask |= DCA_EXSS_X96;
 }
 } else if (s->x96_pos) {
-s->gb = gb;
-s->gb.index = s->x96_pos;
+s->gb = s->gb_in;
+skip_bits_long(&s->gb, s->x96_pos);
 if ((ret = parse_x96_frame(s)) < 0) {
 if (ret == AVERROR(ENOMEM) || (avctx->err_recognition & 
AV_EF_EXPLODE))
 return ret;
diff --git a/libavcodec/dca_core.h b/libavcodec/dca_core.h
index cce0ffd7b1..10128d1e32 100644
--- a/libavcodec/dca_core.h
+++ b/libavcodec/dca_core.h
@@ -101,6 +101,7 @@ typedef struct DCADSPData {
 typedef struct DCACoreDecoder {
 AVCodecContext  *avctx;
 GetBitContext   gb;
+GetBitContext   gb_in;
 
 // Bit stream header
 int crc_present;///< CRC present flag
diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 38a1999fc8..d265cab8df 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -1028,7 +1028,7 @@ static int parse_band_data(DCAXllDecoder *s)
 return ret;
 chs_clear_band_data(s, c, band, seg);
 }
-s->gb.index = navi_pos;
+skip_bits_long(&s->gb, navi_pos - get_bits_count(&s->gb));
 }
 navi_ptr++;
 }
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 456f3c433b..9da8d3b444 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -88,9 +88,9 @@ static inline int ff_dca_check_crc(AVCodecContext *avctx, 
GetBitContext *s,
 
 static inline int ff_dca_seek_bits(GetBitContext *s, int p)
 {
-if (p < s->index || p > s->size_in_bits)
+if (p < get_bits_count(s) || p > s->size_in_bits)
 return -1;
-s->index = p;
+skip_bits_long(s, p - get_bits_count(s));
 return 0;
 }
 

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


[FFmpeg-cvslog] avcodec/dca_core: probe extension headers directly

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:39 2017 
+0300| [902cd30e9b72d3ad5dfe01b27e3dd0928ad88562] | committer: James Almer

avcodec/dca_core: probe extension headers directly

Avoid using bitstream reader in a non-standard way by directly accessing
index. Use bit shifting/masking operations instead.

Signed-off-by: James Almer 

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

 libavcodec/dca_core.c | 31 ---
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 090191dfa9..4a7ea4e3f3 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -1704,6 +1704,7 @@ static int parse_optional_info(DCACoreDecoder *s)
 int sync_pos = FFMIN(s->frame_size / 4, s->gb.size_in_bits / 32) - 1;
 int last_pos = get_bits_count(&s->gb) / 32;
 int size, dist;
+uint32_t w1, w2 = 0;
 
 // Search for extension sync words aligned on 4-byte boundary. Search
 // must be done backwards from the end of core frame to work around
@@ -1718,15 +1719,15 @@ static int parse_optional_info(DCACoreDecoder *s)
 // compatibility with legacy bitstreams. Minimum XCH frame size is
 // 96 bytes. AMODE and PCHS are further checked to reduce
 // probability of alias sync detection.
-for (; sync_pos >= last_pos; sync_pos--) {
-if (AV_RB32(s->gb.buffer + sync_pos * 4) == DCA_SYNCWORD_XCH) {
-s->gb.index = (sync_pos + 1) * 32;
-size = get_bits(&s->gb, 10) + 1;
+for (; sync_pos >= last_pos; sync_pos--, w2 = w1) {
+w1 = AV_RB32(s->gb.buffer + sync_pos * 4);
+if (w1 == DCA_SYNCWORD_XCH) {
+size = (w2 >> 22) + 1;
 dist = s->frame_size - sync_pos * 4;
 if (size >= 96
 && (size == dist || size - 1 == dist)
-&& get_bits(&s->gb, 7) == 0x08) {
-s->xch_pos = get_bits_count(&s->gb);
+&& (w2 >> 15 & 0x7f) == 0x08) {
+s->xch_pos = sync_pos * 32 + 49;
 break;
 }
 }
@@ -1743,13 +1744,13 @@ static int parse_optional_info(DCACoreDecoder *s)
 // The distance between X96 sync word and end of the core frame
 // must be equal to X96 frame size. Minimum X96 frame size is 96
 // bytes.
-for (; sync_pos >= last_pos; sync_pos--) {
-if (AV_RB32(s->gb.buffer + sync_pos * 4) == DCA_SYNCWORD_X96) {
-s->gb.index = (sync_pos + 1) * 32;
-size = get_bits(&s->gb, 12) + 1;
+for (; sync_pos >= last_pos; sync_pos--, w2 = w1) {
+w1 = AV_RB32(s->gb.buffer + sync_pos * 4);
+if (w1 == DCA_SYNCWORD_X96) {
+size = (w2 >> 20) + 1;
 dist = s->frame_size - sync_pos * 4;
 if (size >= 96 && size == dist) {
-s->x96_pos = get_bits_count(&s->gb);
+s->x96_pos = sync_pos * 32 + 44;
 break;
 }
 }
@@ -1768,10 +1769,10 @@ static int parse_optional_info(DCACoreDecoder *s)
 
 // XXCH frame header CRC must be valid. Minimum XXCH frame header
 // size is 11 bytes.
-for (; sync_pos >= last_pos; sync_pos--) {
-if (AV_RB32(s->gb.buffer + sync_pos * 4) == DCA_SYNCWORD_XXCH) 
{
-s->gb.index = (sync_pos + 1) * 32;
-size = get_bits(&s->gb, 6) + 1;
+for (; sync_pos >= last_pos; sync_pos--, w2 = w1) {
+w1 = AV_RB32(s->gb.buffer + sync_pos * 4);
+if (w1 == DCA_SYNCWORD_XXCH) {
+size = (w2 >> 26) + 1;
 dist = s->gb.size_in_bits / 8 - sync_pos * 4;
 if (size >= 11 && size <= dist &&
 !av_crc(dca->crctab, 0x, s->gb.buffer +

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


[FFmpeg-cvslog] avformat/dtsdec: switch to common frame header parsing function

2017-07-18 Thread foo86
ffmpeg | branch: master | foo86  | Mon Jul 10 17:11:36 2017 
+0300| [3b7ec920af42f1dc3676b72db9e617227c220436] | committer: James Almer

avformat/dtsdec: switch to common frame header parsing function

This makes probing for regular DTS more strict because more header
fields are checked and values not supported by decoder are now rejected.

Also fixes an issue original code had with 14-bit streams: 96 bits of
header were expected, however only 84 bits were converted, which was not
enough to parse LFE flag.

Signed-off-by: James Almer 

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

 libavformat/dtsdec.c | 39 +--
 1 file changed, 9 insertions(+), 30 deletions(-)

diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index 8c985b8877..6e0048f9bc 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -35,13 +35,13 @@ static int dts_probe(AVProbeData *p)
 uint32_t state = -1;
 int markers[4*16] = {0};
 int exss_markers = 0, exss_nextpos = 0;
-int sum, max, pos, i;
+int sum, max, pos, ret, i;
 int64_t diff = 0;
-uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
+uint8_t hdr[DCA_CORE_FRAME_HEADER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE] = { 
0 };
 
 for (pos = FFMIN(4096, p->buf_size); pos < p->buf_size - 2; pos += 2) {
-int marker, sample_blocks, sample_rate, sr_code, framesize;
-int lfe, wide_hdr, hdr_size;
+int marker, wide_hdr, hdr_size, framesize;
+DCACoreFrameHeader h;
 GetBitContext gb;
 
 bufp = buf = p->buf + pos;
@@ -98,36 +98,15 @@ static int dts_probe(AVProbeData *p)
 else
 continue;
 
-if (avpriv_dca_convert_bitstream(buf-2, 12, hdr, 12) < 0)
+if ((ret = avpriv_dca_convert_bitstream(buf - 2, 
DCA_CORE_FRAME_HEADER_SIZE,
+hdr, 
DCA_CORE_FRAME_HEADER_SIZE)) < 0)
 continue;
-
-init_get_bits(&gb, hdr, 96);
-skip_bits_long(&gb, 39);
-
-sample_blocks = get_bits(&gb, 7) + 1;
-if (sample_blocks < 8)
+if (init_get_bits8(&gb, hdr, ret) < 0)
 continue;
-
-framesize = get_bits(&gb, 14) + 1;
-if (framesize < 95)
-continue;
-
-skip_bits(&gb, 6);
-sr_code = get_bits(&gb, 4);
-sample_rate = avpriv_dca_sample_rates[sr_code];
-if (sample_rate == 0)
-continue;
-
-get_bits(&gb, 5);
-if (get_bits(&gb, 1))
-continue;
-
-skip_bits_long(&gb, 9);
-lfe = get_bits(&gb, 2);
-if (lfe > 2)
+if (avpriv_dca_parse_core_frame_header(&gb, &h) < 0)
 continue;
 
-marker += 4* sr_code;
+marker += 4 * h.sr_code;
 
 markers[marker] ++;
 }

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


[FFmpeg-cvslog] New commits on branch release/3.0

2017-07-18 Thread Git System
URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4e7ddba5949ab44798271cd5f82ea878a1826540
Author: Michael Niedermayer 
Date:   Sat Jul 15 22:22:52 2017 +0200

avcodec/aacdec_template (fixed point): Check gain in decode_cce() to avoid 
undefined shifts later

Fixes: runtime error: shift exponent 47 is too large for 32-bit type 'int'
Fixes: 2581/clusterfuzz-testcase-minimized-4681474395602944

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 2886142e0c3b5f4304c6e2a2bd282770a8a47f93)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5e78e477fa6902092774a80c14118b9d98568fc4
Author: Michael Niedermayer 
Date:   Fri Jul 14 00:45:29 2017 +0200

avcodec/aacdec_template: Fix undefined integer overflow in apply_tns()

Fixes: runtime error: signed integer overflow: -2147483648 - 1202286525 
cannot be represented in type 'int'
Fixes: 2071/clusterfuzz-testcase-minimized-6036414271586304

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 0ef8f03133a0bd83c74200a8cf30982c0f574016)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9a2ca3cce2cfb74ffdf9fc27405aac24e042df96
Author: Michael Niedermayer 
Date:   Wed Jul 12 16:24:18 2017 +0200

avcodec/mjpegdec: Clip DC also on the negative side.

Fixes: runtime error: signed integer overflow: -16711425 + -2130772346 
cannot be represented in type 'int'
Fixes: 2533/clusterfuzz-testcase-minimized-5372857678823424

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit c28f648b19dd36ff9bc869ad527a1569a0b623e2)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f1143f5dc0e2c65173b102a8cc097b3606bea3d9
Author: Michael Niedermayer 
Date:   Sun Jul 9 15:19:18 2017 +0200

avcodec/aacps (fixed point): Fix multiple signed integer overflows

Fixes: runtime error: signed integer overflow: 1421978265 - -1810326882 
cannot be represented in type 'int'
Fixes: 2527/clusterfuzz-testcase-minimized-5260915396050944

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 80b9e40b6f1e15db9f36c195e7375e65f6b4924f)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0ddff40bf8887a023e553cf6282e9df654435456
Author: Michael Niedermayer 
Date:   Sun Jul 2 03:30:54 2017 +0200

avcodec/sbrdsp_fixed: Fix integer overflow in sbr_hf_apply_noise()

Fixes: runtime error: signed integer overflow: -2049425300 + -117591631 
cannot be represented in type 'int'
Fixes: part of 2096/clusterfuzz-testcase-minimized-4901566068817920

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 2061de8a3f73f14806e5f6ccaf9a635f740a54e6)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2170bdb56d68f792cbeaa61cd85a71249360eea7
Author: Michael Niedermayer 
Date:   Tue Jun 27 13:47:32 2017 +0200

avcodec/wavpack: Fix invalid shift

Fixes: runtime error: left shift of 1 by 31 places cannot be represented in 
type 'int'
Fixes: 2377/clusterfuzz-testcase-minimized-6108505935183872

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit c07af720984acaafaa273369080b458d73975775)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=665885bfc18904fe30500f30d978580cd2e74f68
Author: Michael Niedermayer 
Date:   Fri Jun 30 16:23:32 2017 +0200

avcodec/hevc_ps: Fix integer overflow with beta/tc offsets

Fixes: runtime error: signed integer overflow: 2113929216 * 2 cannot be 
represented in type 'int'
Fixes: 2422/clusterfuzz-testcase-minimized-5242114713583616

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
(cherry picked from commit de54a37c1dfa2817b5838720fac44e82312ccbfd)
Signed-off-by: Michael Niedermayer 

URL:
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7807d2478bfde81a34412dd4f51cc0a9f3a6760f
Author: Michael Niedermayer 
Date:   Wed Jun 28 20:47:59 2017 +0200

avcodec/cfhd: Fix invalid left shift o