[FFmpeg-cvslog] avfilter/x86/vf_v360_init: add missing cases

2020-04-02 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Thu Apr  2 12:03:11 
2020 +0200| [8e1354c95d05a64bf5b99317387fca0ebdb4cd41] | committer: Paul B Mahol

avfilter/x86/vf_v360_init: add missing cases

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

 libavfilter/x86/vf_v360_init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavfilter/x86/vf_v360_init.c b/libavfilter/x86/vf_v360_init.c
index 5b1decd777..7d001a6948 100644
--- a/libavfilter/x86/vf_v360_init.c
+++ b/libavfilter/x86/vf_v360_init.c
@@ -62,7 +62,9 @@ av_cold void ff_v360_init_x86(V360Context *s, int depth)
 s->remap_line = ff_remap3_8bit_line_avx2;
 
 if (EXTERNAL_AVX2_FAST(cpu_flags) && (s->interp == BICUBIC ||
-  s->interp == LANCZOS) && depth <= 8)
+  s->interp == LANCZOS ||
+  s->interp == SPLINE16 ||
+  s->interp == GAUSSIAN) && depth <= 8)
 s->remap_line = ff_remap4_8bit_line_avx2;
 #endif
 }

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

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

[FFmpeg-cvslog] avfilter/vf_v360: add lagrange9 interpolation

2020-04-02 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Tue Mar 31 13:22:10 
2020 +0200| [b00b935d994d8f0a57427c30d6b779e0837dff43] | committer: Paul B Mahol

avfilter/vf_v360: add lagrange9 interpolation

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

 doc/filters.texi  |  2 ++
 libavfilter/v360.h|  1 +
 libavfilter/vf_v360.c | 56 +++
 3 files changed, 59 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 44d41a87cf..a8d5fb1b4e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19105,6 +19105,8 @@ Nearest neighbour.
 @item line
 @item linear
 Bilinear interpolation.
+@item lagrange9
+Lagrange9 interpolation.
 @item cube
 @item cubic
 Bicubic interpolation.
diff --git a/libavfilter/v360.h b/libavfilter/v360.h
index f2f1a47144..e9a47593c9 100644
--- a/libavfilter/v360.h
+++ b/libavfilter/v360.h
@@ -57,6 +57,7 @@ enum Projections {
 enum InterpMethod {
 NEAREST,
 BILINEAR,
+LAGRANGE9,
 BICUBIC,
 LANCZOS,
 SPLINE16,
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index 54d4d23825..3f828d6553 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -112,6 +112,7 @@ static const AVOption v360_options[] = {
 {   "nearest", "nearest neighbour",  0, 
AV_OPT_TYPE_CONST,  {.i64=NEAREST}, 0,   0, FLAGS, 
"interp" },
 {  "line", "bilinear interpolation", 0, 
AV_OPT_TYPE_CONST,  {.i64=BILINEAR},0,   0, FLAGS, 
"interp" },
 {"linear", "bilinear interpolation", 0, 
AV_OPT_TYPE_CONST,  {.i64=BILINEAR},0,   0, FLAGS, 
"interp" },
+{ "lagrange9", "lagrange9 interpolation",0, 
AV_OPT_TYPE_CONST,  {.i64=LAGRANGE9},   0,   0, FLAGS, 
"interp" },
 {  "cube", "bicubic interpolation",  0, 
AV_OPT_TYPE_CONST,  {.i64=BICUBIC}, 0,   0, FLAGS, 
"interp" },
 { "cubic", "bicubic interpolation",  0, 
AV_OPT_TYPE_CONST,  {.i64=BICUBIC}, 0,   0, FLAGS, 
"interp" },
 {  "lanc", "lanczos interpolation",  0, 
AV_OPT_TYPE_CONST,  {.i64=LANCZOS}, 0,   0, FLAGS, 
"interp" },
@@ -313,9 +314,11 @@ static int remap##ws##_##bits##bit_slice(AVFilterContext 
*ctx, void *arg, int jo
 
 DEFINE_REMAP(1,  8)
 DEFINE_REMAP(2,  8)
+DEFINE_REMAP(3,  8)
 DEFINE_REMAP(4,  8)
 DEFINE_REMAP(1, 16)
 DEFINE_REMAP(2, 16)
+DEFINE_REMAP(3, 16)
 DEFINE_REMAP(4, 16)
 
 #define DEFINE_REMAP_LINE(ws, bits, div)   
   \
@@ -346,8 +349,10 @@ static void remap##ws##_##bits##bit_line_c(uint8_t *dst, 
int width, const uint8_
 }
 
 DEFINE_REMAP_LINE(2,  8, 1)
+DEFINE_REMAP_LINE(3,  8, 1)
 DEFINE_REMAP_LINE(4,  8, 1)
 DEFINE_REMAP_LINE(2, 16, 2)
+DEFINE_REMAP_LINE(3, 16, 2)
 DEFINE_REMAP_LINE(4, 16, 2)
 
 void ff_v360_init(V360Context *s, int depth)
@@ -359,6 +364,9 @@ void ff_v360_init(V360Context *s, int depth)
 case BILINEAR:
 s->remap_line = depth <= 8 ? remap2_8bit_line_c : remap2_16bit_line_c;
 break;
+case LAGRANGE9:
+s->remap_line = depth <= 8 ? remap3_8bit_line_c : remap3_16bit_line_c;
+break;
 case BICUBIC:
 case LANCZOS:
 case SPLINE16:
@@ -417,6 +425,47 @@ static void bilinear_kernel(float du, float dv, const 
XYRemap *rmap,
 ker[3] = lrintf(   du  *dv  * 16385.f);
 }
 
+/**
+ * Calculate 1-dimensional lagrange coefficients.
+ *
+ * @param t relative coordinate
+ * @param coeffs coefficients
+ */
+static inline void calculate_lagrange_coeffs(float t, float *coeffs)
+{
+coeffs[0] = (t - 1.f) * (t - 2.f) * 0.5f;
+coeffs[1] = -t * (t - 2.f);
+coeffs[2] =  t * (t - 1.f) * 0.5f;
+}
+
+/**
+ * Calculate kernel for lagrange interpolation.
+ *
+ * @param du horizontal relative coordinate
+ * @param dv vertical relative coordinate
+ * @param rmap calculated 4x4 window
+ * @param u u remap data
+ * @param v v remap data
+ * @param ker ker remap data
+ */
+static void lagrange_kernel(float du, float dv, const XYRemap *rmap,
+int16_t *u, int16_t *v, int16_t *ker)
+{
+float du_coeffs[3];
+float dv_coeffs[3];
+
+calculate_lagrange_coeffs(du, du_coeffs);
+calculate_lagrange_coeffs(dv, dv_coeffs);
+
+for (int i = 0; i < 3; i++) {
+for (int j = 0; j < 3; j++) {
+u[i * 3 + j] = rmap->u[i + 1][j + 1];
+v[i * 3 + j] = rmap->v[i + 1][j + 1];
+ker[i * 3 + j] = lrintf(du_coeffs[j] * dv_coeffs[i] * 16385.f);
+}
+}
+}
+
 /**
  * Calculate 1-dimensional cubic coefficients.
  *
@@ -3689,6 +3738,13 @@ static int config_output(AVFilterLink *outlink)
 sizeof_uv = sizeof(int16_t) * s->elements;
 sizeof_ker = sizeof(int16_t) * s->element

[FFmpeg-cvslog] avfilter/vf_v360: add SIMD for lagrange9 interpolation

2020-04-02 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Tue Mar 31 14:08:20 
2020 +0200| [e4809e12ea57b5551830bc52b37f00caae6352a9] | committer: Paul B Mahol

avfilter/vf_v360: add SIMD for lagrange9 interpolation

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

 libavfilter/x86/vf_v360.asm| 43 ++
 libavfilter/x86/vf_v360_init.c |  6 ++
 2 files changed, 49 insertions(+)

diff --git a/libavfilter/x86/vf_v360.asm b/libavfilter/x86/vf_v360.asm
index 5b241220d8..8e7e4591b4 100644
--- a/libavfilter/x86/vf_v360.asm
+++ b/libavfilter/x86/vf_v360.asm
@@ -165,6 +165,49 @@ DEFINE_ARGS dst, width, src, x, u, v, ker
 
 %if ARCH_X86_64
 
+INIT_YMM avx2
+cglobal remap3_8bit_line, 7, 11, 8, dst, width, src, in_linesize, u, v, ker, 
x, y, tmp, z
+movsxdifnidn widthq, widthd
+xor zq, zq
+xor yq, yq
+xor xq, xq
+movd   xm0, in_linesized
+pcmpeqw m7, m7
+vpbroadcastdm0, xm0
+vpbroadcastdm6, [pd_255]
+
+.loop:
+pmovsxwd   m1, [kerq + yq]
+pmovsxwd   m2, [vq + yq]
+pmovsxwd   m3, [uq + yq]
+
+pmulld  m4, m2, m0
+paddd   m4, m3
+movam3, m7
+vpgatherdd  m2, [srcq + m4], m3
+pandm2, m6
+pmulld  m2, m1
+HADDD   m2, m1
+movzx tmpq, word [vq + yq + 16]
+imul  tmpq, in_linesizeq
+movzx   zq, word [uq + yq + 16]
+add   tmpq, zq
+movzx   zq, byte [srcq + tmpq]
+movzx tmpq, word [kerq + yq + 16]
+imulzd, tmpd
+movd   xm1, zd
+paddd   m2, m1
+psrld   m2, m2, 0xe
+
+packuswbm2, m2
+pextrb   [dstq+xq], xm2, 0
+
+add   xq, 1
+add   yq, 18
+cmp   xq, widthq
+jl .loop
+RET
+
 INIT_YMM avx2
 cglobal remap4_8bit_line, 7, 9, 11, dst, width, src, in_linesize, u, v, ker, 
x, y
 movsxdifnidn widthq, widthd
diff --git a/libavfilter/x86/vf_v360_init.c b/libavfilter/x86/vf_v360_init.c
index babc6c426a..5b1decd777 100644
--- a/libavfilter/x86/vf_v360_init.c
+++ b/libavfilter/x86/vf_v360_init.c
@@ -29,6 +29,9 @@ void ff_remap1_8bit_line_avx2(uint8_t *dst, int width, const 
uint8_t *src, ptrdi
 void ff_remap2_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, 
ptrdiff_t in_linesize,
   const int16_t *const u, const int16_t *const v, 
const int16_t *const ker);
 
+void ff_remap3_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, 
ptrdiff_t in_linesize,
+  const int16_t *const u, const int16_t *const v, 
const int16_t *const ker);
+
 void ff_remap4_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, 
ptrdiff_t in_linesize,
   const int16_t *const u, const int16_t *const v, 
const int16_t *const ker);
 
@@ -55,6 +58,9 @@ av_cold void ff_v360_init_x86(V360Context *s, int depth)
 s->remap_line = ff_remap2_16bit_line_avx2;
 
 #if ARCH_X86_64
+if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == LAGRANGE9 && depth <= 8)
+s->remap_line = ff_remap3_8bit_line_avx2;
+
 if (EXTERNAL_AVX2_FAST(cpu_flags) && (s->interp == BICUBIC ||
   s->interp == LANCZOS) && depth <= 8)
 s->remap_line = ff_remap4_8bit_line_avx2;

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

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

[FFmpeg-cvslog] avformat/matroskaenc: Don't fail if reserved Cues space doesn't suffice

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Mon Dec 30 16:28:39 2019 +0100| [06f108907d75bae89a568eda02e188a91deb4ec9] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Don't fail if reserved Cues space doesn't suffice

When the user opted to write the Cues at the beginning, the Cues were
simply written without checking in advance whether enough space has been
reserved for them. If it wasn't enough, the data following the space
reserved for the Cues was simply overwritten, corrupting the file.

This commit changes this by checking whether enough space has been
reserved for the Cues before outputting anything. If it isn't enough,
no Cues will be output at all and the file will be finalized normally,
yet writing the trailer will nevertheless return an error to notify
the user that his wish of having Cues at the front of the file hasn't
been fulfilled.

This change opens new usecases for this option: It is now safe to use
this option to e.g. record live streams or to use it when muxing the
output of an expensive encoding, because when the reserved space turns
out to be insufficient, one ends up with a file that just lacks Cues
but is otherwise fine.

Signed-off-by: Andreas Rheinhardt 

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

 doc/muxers.texi   |  5 +--
 libavformat/matroskaenc.c | 86 ++-
 2 files changed, 50 insertions(+), 41 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index d304181671..3be1c89416 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1352,8 +1352,9 @@ index at the beginning of the file.
 
 If this option is set to a non-zero value, the muxer will reserve a given 
amount
 of space in the file header and then try to write the cues there when the 
muxing
-finishes. If the available space does not suffice, muxing will fail. A safe 
size
-for most use cases should be about 50kB per hour of video.
+finishes. If the reserved space does not suffice, no Cues will be written, the
+file will be finalized and writing the trailer will return an error.
+A safe size for most use cases should be about 50kB per hour of video.
 
 Note that cues are only written if the output is seekable and this option will
 have no effect if it is not.
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index f3a6dee577..a65a5373b0 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -500,23 +500,15 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int 
stream, int tracknum, i
 return 0;
 }
 
-static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track 
*tracks, int num_tracks)
+static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
+ mkv_cues *cues, mkv_track *tracks, int num_tracks)
 {
-MatroskaMuxContext *mkv = s->priv_data;
-AVIOContext *dyn_cp, *pb = s->pb, *cuepoint;
-int64_t currentpos;
+AVIOContext *cuepoint;
 int ret;
 
-currentpos = avio_tell(pb);
-ret = start_ebml_master_crc32(&dyn_cp, mkv);
-if (ret < 0)
-return ret;
-
 ret = avio_open_dyn_buf(&cuepoint);
-if (ret < 0) {
-ffio_free_dyn_buf(&dyn_cp);
+if (ret < 0)
 return ret;
-}
 
 for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
  entry < end;) {
@@ -535,7 +527,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues 
*cues, mkv_track *tra
 int idx = entry->stream_idx;
 
 av_assert0(idx >= 0 && idx < num_tracks);
-if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type 
!= AVMEDIA_TYPE_SUBTITLE)
+if (tracks[idx].has_cue && streams[idx]->codecpar->codec_type != 
AVMEDIA_TYPE_SUBTITLE)
 continue;
 tracks[idx].has_cue = 1;
 track_positions = start_ebml_master(cuepoint, 
MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE);
@@ -551,9 +543,8 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues 
*cues, mkv_track *tra
 ffio_reset_dyn_buf(cuepoint);
 }
 ffio_free_dyn_buf(&cuepoint);
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES);
 
-return currentpos;
+return 0;
 }
 
 static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, 
AVCodecParameters *par)
@@ -2464,7 +2455,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVIOContext *pb = s->pb;
-int64_t currentpos, cuespos;
+int64_t currentpos;
 int ret;
 
 // check if we have an audio packet cached
@@ -2487,35 +2478,52 @@ static int mkv_write_trailer(AVFormatContext *s)
 
 
 if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
+int64_t ret64;
+
 if (mkv->cues.num_entries) {
-if (mkv->reserve_cues_space) {
-int64_t cues_end;
-
-currentpos = avio_tell(pb);
-

[FFmpeg-cvslog] avformat/matroskaenc: Fix edge case of writing Cues at the beginning

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sat Dec 28 18:39:38 2019 +0100| [b788343446094203773968e5188ca53af5ed5d97] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Fix edge case of writing Cues at the beginning

The Matroska muxer has the ability to write the Cues (the index) at the
beginning of the file (in front of the Cluster): The user inputs the
amount of space that should be reserved at the beginning of the file and
if this is sufficient, the Cues will be written there and the part of the
reserved space not used up by the Cues will be filled with a "Void"
element.

There is just one problem with this: One can not fill a single byte this
way, because said Void element is minimally two bytes long (one byte ID,
one byte length field). Up until now, if one reserved one byte more than
needed, one would run into an assert when writing the Void element.

There are two solutions for this: Error out if it happens. Or adjust the
length field of the Cues in order to ensure that the above situation
can't happen (i.e. write the length on one byte more than necessary).
The first solution is very unsatisfactory, as enough space has been
reserved. Therefore this commit implements the second solution.

Signed-off-by: Andreas Rheinhardt 

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

 libavformat/matroskaenc.c | 42 +++---
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index a65a5373b0..d1edc6756e 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -339,14 +339,15 @@ static int start_ebml_master_crc32(AVIOContext **dyn_cp, 
MatroskaMuxContext *mkv
 }
 
 static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp,
-  MatroskaMuxContext *mkv, uint32_t id)
+  MatroskaMuxContext *mkv, uint32_t id,
+  int length_size)
 {
 uint8_t *buf, crc[4];
 int size, skip = 0;
 
 put_ebml_id(pb, id);
 size = avio_close_dyn_buf(*dyn_cp, &buf);
-put_ebml_num(pb, size, 0);
+put_ebml_num(pb, size, length_size);
 if (mkv->write_crc) {
 skip = 6; /* Skip reserved 6-byte long void element from the dynamic 
buffer. */
 AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, 
buf + skip, size - skip) ^ UINT32_MAX);
@@ -465,7 +466,7 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos);
 end_ebml_master(dyn_cp, seekentry);
 }
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD, 0);
 
 remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
 put_ebml_void(pb, remaining);
@@ -1382,7 +1383,7 @@ static int mkv_write_tracks(AVFormatContext *s)
 end_ebml_master_crc32_preliminary(pb, mkv->tracks_bc,
   MATROSKA_ID_TRACKS, 
&mkv->tracks_pos);
 else
-end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS);
+end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS, 0);
 
 return 0;
 }
@@ -1438,7 +1439,7 @@ static int mkv_write_chapters(AVFormatContext *s)
 end_ebml_master(dyn_cp, chapteratom);
 }
 end_ebml_master(dyn_cp, editionentry);
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CHAPTERS);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CHAPTERS, 0);
 
 mkv->wrote_chapters = 1;
 return 0;
@@ -1637,7 +1638,7 @@ static int mkv_write_tags(AVFormatContext *s)
 end_ebml_master_crc32_preliminary(s->pb, mkv->tags_bc,
   MATROSKA_ID_TAGS, 
&mkv->tags_pos);
 else
-end_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
+end_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS, 
0);
 }
 return 0;
 }
@@ -1733,7 +1734,7 @@ static int mkv_write_attachments(AVFormatContext *s)
 mkv->attachments->entries[mkv->attachments->num_entries].stream_idx = 
i;
 mkv->attachments->entries[mkv->attachments->num_entries++].fileuid  = 
fileuid;
 }
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_ATTACHMENTS);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_ATTACHMENTS, 0);
 
 return 0;
 }
@@ -1874,7 +1875,7 @@ static int mkv_write_header(AVFormatContext *s)
 end_ebml_master_crc32_preliminary(s->pb, mkv->info_bc,
   MATROSKA_ID_INFO, &mkv->info_pos);
 else
-end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv, MATROSKA_ID_INFO);
+end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv, MATROSKA_ID_INFO, 0);
 pb = s->pb;
 
 ret = mkv_write_tracks(s);
@@ -2

[FFmpeg-cvslog] avformat/matroskaenc: Avoid seek when writing Cues at the front

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Dec 29 10:15:19 2019 +0100| [8e4c871196adfb16adf64f826c1291a4b0b0af4f] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Avoid seek when writing Cues at the front

When the Cues are written in front of the Cluster, the muxer would seek
to the beginning (to where the Cues ought to be written) and write the
Cues; afterwards it would seek back to the end of the file only to seek
to the beginning once again to update several elements there. This
commit removes the seek to the end.

Signed-off-by: Andreas Rheinhardt 

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

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

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index d1edc6756e..796383320f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2456,7 +2456,6 @@ static int mkv_write_trailer(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVIOContext *pb = s->pb;
-int64_t currentpos;
 int ret;
 
 // check if we have an audio packet cached
@@ -2479,11 +2478,14 @@ static int mkv_write_trailer(AVFormatContext *s)
 
 
 if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
-int64_t ret64;
+int64_t endpos, ret64;
+
+endpos = avio_tell(pb);
 
 if (mkv->cues.num_entries) {
 AVIOContext *cues;
 uint64_t size;
+int64_t cuespos = endpos;
 int length_size = 0;
 
 ret = start_ebml_master_crc32(&cues, mkv);
@@ -2510,7 +2512,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 ffio_free_dyn_buf(&cues);
 goto after_cues;
 } else {
-currentpos = avio_tell(pb);
+cuespos = mkv->cues_pos;
 if ((ret64 = avio_seek(pb, mkv->cues_pos, SEEK_SET)) < 0) {
 ffio_free_dyn_buf(&cues);
 return ret64;
@@ -2526,18 +2528,16 @@ static int mkv_write_trailer(AVFormatContext *s)
 }
 }
 }
-mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, avio_tell(pb));
+mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, cuespos);
 end_ebml_master_crc32(pb, &cues, mkv, MATROSKA_ID_CUES, 
length_size);
 if (mkv->reserve_cues_space) {
 if (size < mkv->reserve_cues_space)
 put_ebml_void(pb, mkv->reserve_cues_space - size);
-avio_seek(pb, currentpos, SEEK_SET);
-}
+} else
+endpos = avio_tell(pb);
 }
 
 after_cues:
-currentpos = avio_tell(pb);
-
 ret = mkv_write_seekhead(pb, mkv, 1, mkv->info_pos);
 if (ret < 0)
 return ret;
@@ -2583,7 +2583,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 end_ebml_master_crc32(pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS, 0);
 }
 
-avio_seek(pb, currentpos, SEEK_SET);
+avio_seek(pb, endpos, SEEK_SET);
 }
 
 if (!mkv->is_live) {

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

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

[FFmpeg-cvslog] avformat/matroskaenc: Simplify writing Void elements

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Jan 12 01:30:58 2020 +0100| [98a6c6ec82eae39cffebd16e8862bf269bec1abc] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Simplify writing Void elements

Reserving space in Matroska works by writing a Void element. And until
now this worked as follows: The current position was recorded and the
EBML ID as well as the length field written; then the new position was
recorded to know how much more to write. Afterwards the actual writing
has been performed via ffio_fill().

But it is unnecessary to explicitly use the positions (obtained via
avio_tell()) to find out how much still needs to be written, because the
length of the ID and the length field are known. So rewrite the function
to no longer use them.

Also, given that ffio_fill() uses an int parameter and given that no
current caller (and no sane future caller) will want to reserve several
GB of space, make the size parameter of put_ebml_void() itself an int.

Signed-off-by: Andreas Rheinhardt 

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

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

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 796383320f..832b272033 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -288,21 +288,22 @@ static void put_ebml_string(AVIOContext *pb, uint32_t 
elementid,
  *
  * @param size The number of bytes to reserve, which must be at least 2.
  */
-static void put_ebml_void(AVIOContext *pb, uint64_t size)
+static void put_ebml_void(AVIOContext *pb, int size)
 {
-int64_t currentpos = avio_tell(pb);
-
 av_assert0(size >= 2);
 
 put_ebml_id(pb, EBML_ID_VOID);
 // we need to subtract the length needed to store the size from the
 // size we need to reserve so 2 cases, we use 8 bytes to store the
 // size if possible, 1 byte otherwise
-if (size < 10)
-put_ebml_num(pb, size - 2, 0);
-else
-put_ebml_num(pb, size - 9, 8);
-ffio_fill(pb, 0, currentpos + size - avio_tell(pb));
+if (size < 10) {
+size -= 2;
+put_ebml_num(pb, size, 0);
+} else {
+size -= 9;
+put_ebml_num(pb, size, 8);
+}
+ffio_fill(pb, 0, size);
 }
 
 static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid,

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

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

[FFmpeg-cvslog] avformat/matroskaenc: Combine checks for audio

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Jan 17 20:14:24 2020 +0100| [0d4b3b4c023b1b13a78e650f81845fb8e25f456c] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Combine checks for audio

mkv_write_track() currently has three places where it checks for whether
the current codec type is audio: One in a switch and two outside of it.
These checks can be combined by moving the code after the other two checks
inside the audio-related part of the switch.

Signed-off-by: Andreas Rheinhardt 

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

 libavformat/matroskaenc.c | 59 +++
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 832b272033..ec9f4cfdf4 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1091,7 +1091,7 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 ebml_master subinfo, track;
 int native_id = 0;
 int qt_id = 0;
-int bit_depth = av_get_bits_per_sample(par->codec_id);
+int bit_depth;
 int sample_rate = par->sample_rate;
 int output_sample_rate = 0;
 int display_width_div = 1;
@@ -1104,17 +1104,6 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 return 0;
 }
 
-if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
-if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) {
-if (par->bits_per_raw_sample)
-bit_depth = par->bits_per_raw_sample;
-else
-bit_depth = av_get_bytes_per_sample(par->format) << 3;
-}
-if (!bit_depth)
-bit_depth = par->bits_per_coded_sample;
-}
-
 if (par->codec_id == AV_CODEC_ID_AAC) {
 ret = get_aac_sample_rates(s, par->extradata, par->extradata_size, 
&sample_rate,
&output_sample_rate);
@@ -1201,24 +1190,6 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 }
 }
 
-if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->initial_padding && 
par->codec_id == AV_CODEC_ID_OPUS) {
-int64_t codecdelay = av_rescale_q(par->initial_padding,
-  (AVRational){ 1, 48000 },
-  (AVRational){ 1, 10 });
-if (codecdelay < 0) {
-av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
-return AVERROR(EINVAL);
-}
-// mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding,
-// (AVRational){ 1, 
par->sample_rate },
-// st->time_base);
-
-put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
-}
-if (par->codec_id == AV_CODEC_ID_OPUS) {
-put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL);
-}
-
 switch (par->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
 mkv->have_video = 1;
@@ -1312,6 +1283,24 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 break;
 
 case AVMEDIA_TYPE_AUDIO:
+if (par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) {
+int64_t codecdelay = av_rescale_q(par->initial_padding,
+  (AVRational){ 1, 48000 },
+  (AVRational){ 1, 10 });
+if (codecdelay < 0) {
+av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
+return AVERROR(EINVAL);
+}
+// mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding,
+// (AVRational){ 1, 
par->sample_rate },
+// st->time_base);
+
+put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
+}
+if (par->codec_id == AV_CODEC_ID_OPUS) {
+put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL);
+}
+
 put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_AUDIO);
 
 if (!native_id)
@@ -1325,6 +1314,16 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate);
 if (output_sample_rate)
 put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, 
output_sample_rate);
+
+bit_depth = av_get_bits_per_sample(par->codec_id);
+if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) {
+if (par->bits_per_raw_sample)
+bit_depth = par->bits_per_raw_sample;
+else
+bit_depth = av_get_bytes_per_sample(par->format) << 3;
+}
+if (!bit_depth)
+bit_depth = par->bits_per_coded_sample;
 if (bit_depth)
 put_ebml_uint(pb, MATROSKA_ID_AUDIOBITDEPTH,

[FFmpeg-cvslog] avformat/matroskaenc: Reindent after previous commit

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Jan 17 20:40:15 2020 +0100| [bc52ce309dfcec6151bf1776e6a256f547285700] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Reindent after previous commit

Also remove { } after an if if there is only one statement inside { }.

Signed-off-by: Andreas Rheinhardt 

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

 libavformat/matroskaenc.c | 29 ++---
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index ec9f4cfdf4..d3075d7ec4 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1284,22 +1284,21 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 
 case AVMEDIA_TYPE_AUDIO:
 if (par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) {
-int64_t codecdelay = av_rescale_q(par->initial_padding,
-  (AVRational){ 1, 48000 },
-  (AVRational){ 1, 10 });
-if (codecdelay < 0) {
-av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
-return AVERROR(EINVAL);
-}
-// mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding,
-// (AVRational){ 1, 
par->sample_rate },
-// st->time_base);
+int64_t codecdelay = av_rescale_q(par->initial_padding,
+  (AVRational){ 1, 48000 },
+  (AVRational){ 1, 10 });
+if (codecdelay < 0) {
+av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
+return AVERROR(EINVAL);
+}
+//mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding,
+//(AVRational){ 1, 
par->sample_rate },
+//st->time_base);
 
-put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
-}
-if (par->codec_id == AV_CODEC_ID_OPUS) {
-put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL);
-}
+put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
+}
+if (par->codec_id == AV_CODEC_ID_OPUS)
+put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL);
 
 put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_AUDIO);
 

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

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

[FFmpeg-cvslog] avformat/matroskaenc: Don't implicitly mark WebVTT in WebM as English

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sat Jan 18 02:19:46 2020 +0100| [da4ba2431c92017379a0bd0b3c0fb74ce6093f09] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Don't implicitly mark WebVTT in WebM as English

Writing the language of WebVTT in WebM proceeded differently than the
language of all other tracks: In case no language was given, it does not
write anything instead of "und" (for undefined). Because the default
value of the Language element in WebM (that inherited it from Matroska)
is "eng" (for English), any such track will actually be flagged as
English.

Doing it this way goes back to commit 509642b4 (the commit adding
support for WebVTT) and no reason for this has been given in the commit
message or in the discussion about this patch on the mailing list; the
best I can think of is this: the WebM wiki contains "The srclang attribute
is stored as the Language sub-element." Someone unfamiliar with default
values in Matroska/WebM could interpret this as meaning that no Language
element should be written if the language is unknown. And this is wrong
and this commit changes it.

Signed-off-by: Andreas Rheinhardt 

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

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

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index d3075d7ec4..07652d69f1 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1121,11 +1121,8 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 if ((tag = av_dict_get(st->metadata, "title", NULL, 0)))
 put_ebml_string(pb, MATROSKA_ID_TRACKNAME, tag->value);
 tag = av_dict_get(st->metadata, "language", NULL, 0);
-if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) {
-put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag && tag->value ? 
tag->value:"und");
-} else if (tag && tag->value) {
-put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag->value);
-}
+put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE,
+tag && tag->value ? tag->value : "und");
 
 // The default value for TRACKFLAGDEFAULT is 1, so add element
 // if we need to clear it.

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

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

[FFmpeg-cvslog] avformat/hnm: Only keep and parse what is needed later

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sat Mar 21 06:17:36 2020 +0100| [d20378373ea26c48078fbac6d6a59f8592eadacc] | 
committer: Andreas Rheinhardt

avformat/hnm: Only keep and parse what is needed later

The hnm demuxer's context struct contained lots of fields that are
write-only variables or that are not used outside of parsing the header
and that can therefore be replaced by local variables of hnm_read_header().
This commit removes all of these from the context; the second type has
been replaced by local variables.

An AVPacket (that was initialized when reading the header and for which
dead code to unreference it existed in hnm_read_close()) is among the
removed things. Removing it allowed to remove hnm_read_close()
altogether and also removes another instance of usage of sizeof(AVPacket).

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

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

 libavformat/hnm.c | 63 +++
 1 file changed, 12 insertions(+), 51 deletions(-)

diff --git a/libavformat/hnm.c b/libavformat/hnm.c
index 31221553a4..f06add5cf8 100644
--- a/libavformat/hnm.c
+++ b/libavformat/hnm.c
@@ -37,19 +37,9 @@
 #define HNM4_CHUNK_ID_SD 17491
 
 typedef struct Hnm4DemuxContext {
-uint8_t version;
-uint16_t width;
-uint16_t height;
-uint32_t filesize;
 uint32_t frames;
-uint32_t taboffset;
-uint16_t bits;
-uint16_t channels;
-uint32_t framesize;
 uint32_t currentframe;
-int64_t pts;
 uint32_t superchunk_remaining;
-AVPacket vpkt;
 } Hnm4DemuxContext;
 
 static int hnm_probe(const AVProbeData *p)
@@ -69,55 +59,37 @@ static int hnm_read_header(AVFormatContext *s)
 {
 Hnm4DemuxContext *hnm = s->priv_data;
 AVIOContext *pb = s->pb;
+unsigned width, height;
 AVStream *vst;
 int ret;
 
-/* default context members */
-hnm->pts = 0;
-av_init_packet(&hnm->vpkt);
-hnm->vpkt.data = NULL;
-hnm->vpkt.size = 0;
-
-hnm->superchunk_remaining = 0;
-
 avio_skip(pb, 8);
-hnm->width = avio_rl16(pb);
-hnm->height= avio_rl16(pb);
-hnm->filesize  = avio_rl32(pb);
+width  = avio_rl16(pb);
+height = avio_rl16(pb);
+avio_rl32(pb); // filesize
 hnm->frames= avio_rl32(pb);
-hnm->taboffset = avio_rl32(pb);
-hnm->bits  = avio_rl16(pb);
-hnm->channels  = avio_rl16(pb);
-hnm->framesize = avio_rl32(pb);
-avio_skip(pb, 32);
+avio_skip(pb, 44);
 
-hnm->currentframe = 0;
-
-if (hnm->width  < 256 || hnm->width  > 640 ||
-hnm->height < 150 || hnm->height > 480) {
+if (width  < 256 || width  > 640 ||
+height < 150 || height > 480) {
 av_log(s, AV_LOG_ERROR,
-   "invalid resolution: %ux%u\n", hnm->width, hnm->height);
+   "invalid resolution: %ux%u\n", width, height);
 return AVERROR_INVALIDDATA;
 }
 
-// TODO: find a better way to detect HNM4A
-if (hnm->width == 640)
-hnm->version = 0x4a;
-else
-hnm->version = 0x40;
-
 if (!(vst = avformat_new_stream(s, NULL)))
 return AVERROR(ENOMEM);
 
 vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 vst->codecpar->codec_id   = AV_CODEC_ID_HNM4_VIDEO;
 vst->codecpar->codec_tag  = 0;
-vst->codecpar->width  = hnm->width;
-vst->codecpar->height = hnm->height;
+vst->codecpar->width  = width;
+vst->codecpar->height = height;
 if ((ret = ff_alloc_extradata(vst->codecpar, 1)) < 0)
 return ret;
 
-vst->codecpar->extradata[0] = hnm->version;
+// TODO: find a better way to detect HNM4A
+vst->codecpar->extradata[0] = width == 640 ? 0x4a : 0x40;
 
 vst->start_time = 0;
 
@@ -186,16 +158,6 @@ static int hnm_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 return ret;
 }
 
-static int hnm_read_close(AVFormatContext *s)
-{
-Hnm4DemuxContext *hnm = s->priv_data;
-
-if (hnm->vpkt.size > 0)
-av_packet_unref(&hnm->vpkt);
-
-return 0;
-}
-
 AVInputFormat ff_hnm_demuxer = {
 .name   = "hnm",
 .long_name  = NULL_IF_CONFIG_SMALL("Cryo HNM v4"),
@@ -203,6 +165,5 @@ AVInputFormat ff_hnm_demuxer = {
 .read_probe = hnm_probe,
 .read_header= hnm_read_header,
 .read_packet= hnm_read_packet,
-.read_close = hnm_read_close,
 .flags  = AVFMT_NO_BYTE_SEEK | AVFMT_NOGENSEARCH | 
AVFMT_NOBINSEARCH
 };

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

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

[FFmpeg-cvslog] fate/matroska: Add test for updating CodecPrivate from packet sidedata

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Apr  1 20:22:29 2020 +0200| [45cb93e9bddcd6395171e99717623e9adbcf700e] | 
committer: Andreas Rheinhardt

fate/matroska: Add test for updating CodecPrivate from packet sidedata

containing updated extradata, in this case a new FLAC streaminfo.
Furthermore, it also tests that the Matroska muxer is able to preserve
uncommon channel layouts by adding Vorbis comments to the CodecPrivate.

Signed-off-by: Andreas Rheinhardt 

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

 tests/fate/matroska.mak   | 12 ++
 tests/ref/fate/matroska-flac-extradata-update | 53 +++
 2 files changed, 65 insertions(+)

diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index 93b5bff89a..4b9ee7a872 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -37,6 +37,18 @@ fate-matroska-lzo-decompression: CMD = framecrc -i 
$(TARGET_SAMPLES)/mkv/lzo.mka
 FATE_MATROSKA-$(call ALLYES, MATROSKA_DEMUXER FLAC_PARSER) += 
fate-matroska-flac-channel-mapping
 fate-matroska-flac-channel-mapping: CMD = framecrc -i 
$(TARGET_SAMPLES)/mkv/flac_channel_layouts.mka -map 0 -c:a copy
 
+# This tests that the Matroska muxer writes the channel layout
+# of FLAC tracks as a Vorbis comment in the CodecPrivate if necessary
+# and that FLAC extradata is correctly updated when a packet
+# with sidedata containing new extradata is encountered.
+# Furthermore it tests everything the matroska-flac-channel-mapping test
+# tests and it also tests the FLAC decoder and encoder, in particular
+# the latter's ability to send updated extradata.
+FATE_MATROSKA-$(call ALLYES, FLAC_DECODER FLAC_ENCODER FLAC_PARSER \
+MATROSKA_DEMUXER MATROSKA_MUXER) += 
fate-matroska-flac-extradata-update
+fate-matroska-flac-extradata-update: CMD = transcode matroska 
$(TARGET_SAMPLES)/mkv/flac_channel_layouts.mka \
+   matroska "-map 0 -map 0:0 -c flac 
-frames:a:2 8" "-map 0 -c copy"
+
 FATE_MATROSKA_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER) += 
fate-matroska-spherical-mono
 fate-matroska-spherical-mono: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-show_entries stream_side_data_list -select_streams v -v 0 
$(TARGET_SAMPLES)/mkv/spherical.mkv
 
diff --git a/tests/ref/fate/matroska-flac-extradata-update 
b/tests/ref/fate/matroska-flac-extradata-update
new file mode 100644
index 00..743486c974
--- /dev/null
+++ b/tests/ref/fate/matroska-flac-extradata-update
@@ -0,0 +1,53 @@
+2b363aecd6422c3ce9964983f5d0f3ef 
*tests/data/fate/matroska-flac-extradata-update.matroska
+2049 tests/data/fate/matroska-flac-extradata-update.matroska
+#extradata 0:   34, 0x7acb09e7
+#extradata 1:   34, 0x7acb09e7
+#extradata 2:   34, 0x443402dd
+#tb 0: 1/1000
+#media_type 0: audio
+#codec_id 0: flac
+#sample_rate 0: 48000
+#channel_layout 0: 3f
+#channel_layout_name 0: 5.1
+#tb 1: 1/1000
+#media_type 1: audio
+#codec_id 1: flac
+#sample_rate 1: 48000
+#channel_layout 1: 60f
+#channel_layout_name 1: 5.1(side)
+#tb 2: 1/1000
+#media_type 2: audio
+#codec_id 2: flac
+#sample_rate 2: 48000
+#channel_layout 2: 3f
+#channel_layout_name 2: 5.1
+0,  0,  0,   96,   26, 0x4e160341
+1,  0,  0,   96,   26, 0x4e160341
+2,  0,  0,   96,   26, 0x4e160341
+0, 96, 96,   96,   26, 0x4e17035c
+1, 96, 96,   96,   26, 0x4e17035c
+2, 96, 96,   96,   26, 0x4e17035c
+0,192,192,   96,   26, 0x4de40383
+1,192,192,   96,   26, 0x4de40383
+2,192,192,   96,   26, 0x4de40383
+0,288,288,   96,   26, 0x4e3903a2
+1,288,288,   96,   26, 0x4e3903a2
+2,288,288,   96,   26, 0x4e3903a2
+0,384,384,   96,   26, 0x4f9a03d5
+1,384,384,   96,   26, 0x4f9a03d5
+2,384,384,   96,   26, 0x4f9a03d5
+0,480,480,   96,   26, 0x501303e0
+1,480,480,   96,   26, 0x501303e0
+2,480,480,   96,   26, 0x501303e0
+0,576,576,   96,   26, 0x5160042f
+1,576,576,   96,   26, 0x5160042f
+2,576,576,   96,   26, 0x5160042f
+0,672,672,   96,   26, 0x50dd042e
+1,672,672,   96,   26, 0x50dd042e
+2,672,672,   96,   26, 0x50dd042e
+0,768,768,   96,   26, 0x53de0499
+1,768,768,   96,   26, 0x53de0499
+0,864,864,   96,   26, 0x53df04b4
+1,864,864,   96,   26, 0x53df04b4
+0,960,960,   42,   26, 0x5740044b
+1,960,960,   42,   26, 0x574

[FFmpeg-cvslog] libavformat/amr.c: Check return value from avio_read()

2020-04-02 Thread John Rummell
ffmpeg | branch: master | John Rummell  | Mon Mar 30 
21:30:33 2020 -0700| [5b967f56b6d85f62446836fc8ef64d0dcfcbda17] | committer: 
Michael Niedermayer

libavformat/amr.c: Check return value from avio_read()

If the buffer doesn't contain enough bytes when reading a stream,
fail rather than continuing on with initialized data. Caught by
Chromium fuzzeras (crbug.com/1065731).

Signed-off-by: Michael Niedermayer 

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

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

diff --git a/libavformat/amr.c b/libavformat/amr.c
index eccbbde5b0..b8a5debb16 100644
--- a/libavformat/amr.c
+++ b/libavformat/amr.c
@@ -89,13 +89,15 @@ static int amr_read_header(AVFormatContext *s)
 AVStream *st;
 uint8_t header[9];
 
-avio_read(pb, header, 6);
+if (avio_read(pb, header, 6) != 6)
+return AVERROR_INVALIDDATA;
 
 st = avformat_new_stream(s, NULL);
 if (!st)
 return AVERROR(ENOMEM);
 if (memcmp(header, AMR_header, 6)) {
-avio_read(pb, header + 6, 3);
+if (avio_read(pb, header + 6, 3) != 3)
+return AVERROR_INVALIDDATA;
 if (memcmp(header, AMRWB_header, 9)) {
 return -1;
 }

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

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

[FFmpeg-cvslog] swscale/swscale: remove useless code

2020-04-02 Thread Ruiling Song
ffmpeg | branch: master | Ruiling Song  | Wed Apr  1 
15:32:15 2020 +0800| [4700f7d6fce3ae3fcce86e069edf16b6cbae614b] | committer: 
Michael Niedermayer

swscale/swscale: remove useless code

Signed-off-by: Ruiling Song 
Signed-off-by: Michael Niedermayer 

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

 libswscale/swscale.c  | 16 +---
 libswscale/swscale_internal.h |  5 +
 libswscale/x86/swscale.c  |  3 +--
 3 files changed, 3 insertions(+), 21 deletions(-)

diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index 8436f056d4..001cfbf15b 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -266,8 +266,6 @@ static int swscale(SwsContext *c, const uint8_t *src[],
 
 /* vars which will change and which we need to store back in the context */
 int dstY = c->dstY;
-int lumBufIndex  = c->lumBufIndex;
-int chrBufIndex  = c->chrBufIndex;
 int lastInLumBuf = c->lastInLumBuf;
 int lastInChrBuf = c->lastInChrBuf;
 
@@ -336,8 +334,6 @@ static int swscale(SwsContext *c, const uint8_t *src[],
  * will not get executed. This is not really intended but works
  * currently, so people might do it. */
 if (srcSliceY == 0) {
-lumBufIndex  = -1;
-chrBufIndex  = -1;
 dstY = 0;
 lastInLumBuf = -1;
 lastInChrBuf = -1;
@@ -461,7 +457,6 @@ static int swscale(SwsContext *c, const uint8_t *src[],
 desc[i].process(c, &desc[i], firstPosY, lastPosY - firstPosY + 
1);
 }
 
-lumBufIndex += lastLumSrcY - lastInLumBuf;
 lastInLumBuf = lastLumSrcY;
 
 if (cPosY < lastChrSrcY + 1) {
@@ -469,20 +464,13 @@ static int swscale(SwsContext *c, const uint8_t *src[],
 desc[i].process(c, &desc[i], firstCPosY, lastCPosY - 
firstCPosY + 1);
 }
 
-chrBufIndex += lastChrSrcY - lastInChrBuf;
 lastInChrBuf = lastChrSrcY;
 
-// wrap buf index around to stay inside the ring buffer
-if (lumBufIndex >= vLumFilterSize)
-lumBufIndex -= vLumFilterSize;
-if (chrBufIndex >= vChrFilterSize)
-chrBufIndex -= vChrFilterSize;
 if (!enough_lines)
 break;  // we can't output a dstY line so let's try with the next 
slice
 
 #if HAVE_MMX_INLINE
-ff_updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex,
-  lastInLumBuf, lastInChrBuf);
+ff_updateMMXDitherTables(c, dstY);
 #endif
 if (should_dither) {
 c->chrDither8 = ff_dither_8x8_128[chrDstY & 7];
@@ -524,8 +512,6 @@ static int swscale(SwsContext *c, const uint8_t *src[],
 
 /* store changed local vars back in the context */
 c->dstY = dstY;
-c->lumBufIndex  = lumBufIndex;
-c->chrBufIndex  = chrBufIndex;
 c->lastInLumBuf = lastInLumBuf;
 c->lastInChrBuf = lastInChrBuf;
 
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index a59d12745a..9dda53eead 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -350,8 +350,6 @@ typedef struct SwsContext {
 //@{
 int lastInLumBuf; ///< Last scaled horizontal luma/alpha line 
from source in the ring buffer.
 int lastInChrBuf; ///< Last scaled horizontal chroma line 
from source in the ring buffer.
-int lumBufIndex;  ///< Index in ring buffer of the last scaled 
horizontal luma/alpha line from source.
-int chrBufIndex;  ///< Index in ring buffer of the last scaled 
horizontal chroma line from source.
 //@}
 
 uint8_t *formatConvBuffer;
@@ -635,8 +633,7 @@ int ff_yuv2rgb_c_init_tables(SwsContext *c, const int 
inv_table[4],
 void ff_yuv2rgb_init_tables_ppc(SwsContext *c, const int inv_table[4],
 int brightness, int contrast, int saturation);
 
-void ff_updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int 
chrBufIndex,
-   int lastInLumBuf, int lastInChrBuf);
+void ff_updateMMXDitherTables(SwsContext *c, int dstY);
 
 av_cold void ff_sws_init_range_convert(SwsContext *c);
 
diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c
index e9d474a1e8..61110839ee 100644
--- a/libswscale/x86/swscale.c
+++ b/libswscale/x86/swscale.c
@@ -79,8 +79,7 @@ DECLARE_ASM_ALIGNED(8, const uint64_t, ff_w)= 
0x0001000100010001ULL;
 #include "swscale_template.c"
 #endif
 
-void ff_updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int 
chrBufIndex,
-   int lastInLumBuf, int lastInChrBuf)
+void ff_updateMMXDitherTables(SwsContext *c, int dstY)
 {
 const int dstH= c->dstH;
 const int flags= c->flags;

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

To unsubscribe, visit link above, or email
ffmpeg-cvslo

[FFmpeg-cvslog] configure: Do not abort when cross-compiling to the native CPU

2020-04-02 Thread David Michael
ffmpeg | branch: master | David Michael  | Wed Apr  1 
00:07:55 2020 -0400| [9f567c431eb49e5cd4399f54de433422f5b9b9c4] | committer: 
Michael Niedermayer

configure: Do not abort when cross-compiling to the native CPU

Using a compiler with a different host triplet is considered
cross-compiling, even when it is for the same architecture as the
build system.  With such a cross-compiler, it is still valid to
optimize builds with --cpu=host.  Make the condition that aborts in
this case into a warning instead, since a cross-compiler for an
incompatible architecture will fail with -mtune=native anyway.

Signed-off-by: David Michael 
Signed-off-by: Michael Niedermayer 

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

 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 21827eeb45..251b6a977a 100755
--- a/configure
+++ b/configure
@@ -4797,7 +4797,7 @@ fi
 
 if test "$cpu" = host; then
 enabled cross_compile &&
-die "--cpu=host makes no sense when cross-compiling."
+warn "--cpu=host makes no sense when cross-compiling."
 
 case "$cc_type" in
 gcc|llvm_gcc)

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

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

[FFmpeg-cvslog] configure: fix build issue of vf_dnn_processing.c when --disable-swscale

2020-04-02 Thread Guo , Yejun
ffmpeg | branch: master | Guo, Yejun  | Thu Apr  2 
11:18:08 2020 +0800| [e1488700a25f59c3bd7ec709a48cfc69c3debd1b] | committer: 
Guo, Yejun

configure: fix build issue of vf_dnn_processing.c when --disable-swscale

vf_dnn_processing.c recently changed to use swscale to trasfer data
between AVFrame and dnn model.

Signed-off-by: Guo, Yejun 
Signed-off-by: Linjie Fu 

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

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

diff --git a/configure b/configure
index 251b6a977a..5fe9950e20 100755
--- a/configure
+++ b/configure
@@ -3498,6 +3498,7 @@ derain_filter_select="dnn"
 deshake_filter_select="pixelutils"
 deshake_opencl_filter_deps="opencl"
 dilation_opencl_filter_deps="opencl"
+dnn_processing_filter_deps="swscale"
 dnn_processing_filter_select="dnn"
 drawtext_filter_deps="libfreetype"
 drawtext_filter_suggest="libfontconfig libfribidi"

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

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

[FFmpeg-cvslog] avformat/matroskaenc: Stop reallocating of Cluster buffer

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Dec 29 01:01:52 2019 +0100| [4aa0665f393847c35387a1c673e62346d0acfc95] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Stop reallocating of Cluster buffer

The Matroska muxer uses a dynamic buffer to buffer the content of
Clusters before eventually writing them. Up until now, each time a
Cluster was written, the dynamic buffer was closed, i.e. freed; now it
is only reset, saving allocations of the AVIOContext itself, its opaque
as well as most of the reallocations of the buffer.

This is advantageous performance-wise, in particular on systems where
reallocations are slow (namely Windows). The following table shows the
decicyles for writing a frame on Linux (Ubuntu 19.10) and Windows (7)
on an x64 Haswell (to /dev/null on Linux, to stdout which is discarded
on Windows (the default values of the size and duration of clusters for
seekable output have been explicitly set in this case); in all tests,
writing CRC-32 values has been disabled in all tests; calls to the muxer's
write_packet function in write_packet() in libavformat/mux.c have been
timed; each of the following tests has been repeated 50 times):

| Windows before | Windows after | Linux before | Linux after
_
 A  | 979437 |192304 |259500|   183320
 B  | 715936 |155648 |152786|   130879
 C  | 265115 | 56034 | 78496|53243
 D  | 386224 | 80307 |128894|75354
 E  |  21732 | 10695 | 11320| 9801

(A is a 10.2 mb/s file with a GOP length of 2s, amounting to an average
Cluster size of about 2.5 MiB; the average Cluster size of B is 1.1 MiB;
for C it is 2.35 MiB, for D it is 0.46 MiB; for E - a file with just a
single audio track of 158kb/s resulting in a Cluster size of about 100
kB, the relative gains were the smallest, probably because of the small
Cluster size.)

Signed-off-by: Andreas Rheinhardt 

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

 libavformat/matroskaenc.c | 47 ++-
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 07652d69f1..f833fda14c 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -330,7 +330,7 @@ static int start_ebml_master_crc32(AVIOContext **dyn_cp, 
MatroskaMuxContext *mkv
 {
 int ret;
 
-if ((ret = avio_open_dyn_buf(dyn_cp)) < 0)
+if (!*dyn_cp && (ret = avio_open_dyn_buf(dyn_cp)) < 0)
 return ret;
 
 if (mkv->write_crc)
@@ -341,13 +341,13 @@ static int start_ebml_master_crc32(AVIOContext **dyn_cp, 
MatroskaMuxContext *mkv
 
 static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp,
   MatroskaMuxContext *mkv, uint32_t id,
-  int length_size)
+  int length_size, int keep_buffer)
 {
 uint8_t *buf, crc[4];
 int size, skip = 0;
 
 put_ebml_id(pb, id);
-size = avio_close_dyn_buf(*dyn_cp, &buf);
+size = avio_get_dyn_buf(*dyn_cp, &buf);
 put_ebml_num(pb, size, length_size);
 if (mkv->write_crc) {
 skip = 6; /* Skip reserved 6-byte long void element from the dynamic 
buffer. */
@@ -356,8 +356,11 @@ static void end_ebml_master_crc32(AVIOContext *pb, 
AVIOContext **dyn_cp,
 }
 avio_write(pb, buf + skip, size - skip);
 
-av_free(buf);
-*dyn_cp = NULL;
+if (keep_buffer) {
+ffio_reset_dyn_buf(*dyn_cp);
+} else {
+ffio_free_dyn_buf(dyn_cp);
+}
 }
 
 /**
@@ -443,7 +446,7 @@ static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, 
uint32_t elementid,
 static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv,
   int error_on_seek_failure, int64_t destpos)
 {
-AVIOContext *dyn_cp;
+AVIOContext *dyn_cp = NULL;
 mkv_seekhead *seekhead = &mkv->seekhead;
 int64_t remaining, ret64;
 int i, ret;
@@ -467,7 +470,7 @@ static int mkv_write_seekhead(AVIOContext *pb, 
MatroskaMuxContext *mkv,
 put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos);
 end_ebml_master(dyn_cp, seekentry);
 }
-end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD, 0);
+end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD, 0, 0);
 
 remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
 put_ebml_void(pb, remaining);
@@ -1379,7 +1382,7 @@ static int mkv_write_tracks(AVFormatContext *s)
 end_ebml_master_crc32_preliminary(pb, mkv->tracks_bc,
   MATROSKA_ID_TRACKS, 
&mkv->tracks_pos);
 else
-end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS, 0);
+end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv,

[FFmpeg-cvslog] avformat/matroskaenc: Remove unnecessary avio_tell(), avio_seek()

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Jan 22 18:45:08 2020 +0100| [0fc150f048398c9dbb8578f25e916fd356c18a54] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Remove unnecessary avio_tell(), avio_seek()

avio_close_dyn_buf() has a bug: When the write pointer does not point to
the end of the written data when calling it (i.e. when one has performed
a seek back to update already written data), it would not add padding to
the end of the buffer, but to the current position, overwriting other
data; furthermore the reported size would be wrong (off by the amount of
data it has overwritten with padding).

In order not to run into this when updating already written elements or
elements for which size has only been reserved, the Matroska muxer would
first record the current position of the dynamic buffer, then seek to
the desired position, perform the update and seek back to the earlier
position.

But now that end_ebml_master_crc32() does not make use of
avio_close_dyn_buf() any more, this is no longer necessary.

Signed-off-by: Andreas Rheinhardt 

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

 libavformat/matroskaenc.c | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index f833fda14c..223406ce75 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2182,7 +2182,6 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 case AV_CODEC_ID_AAC:
 if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && 
!mkv->is_live) {
 int filler, output_sample_rate = 0;
-int64_t curpos;
 ret = get_aac_sample_rates(s, side_data, side_data_size, 
&track->sample_rate,
&output_sample_rate);
 if (ret < 0)
@@ -2193,7 +2192,6 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 if (ret < 0)
 return ret;
 memcpy(par->extradata, side_data, side_data_size);
-curpos = avio_tell(mkv->tracks_bc);
 avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET);
 mkv_write_codecprivate(s, mkv->tracks_bc, par, 1, 0);
 filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(mkv->tracks_bc) - 
track->codecpriv_offset);
@@ -2202,7 +2200,6 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 avio_seek(mkv->tracks_bc, track->sample_rate_offset, SEEK_SET);
 put_ebml_float(mkv->tracks_bc, MATROSKA_ID_AUDIOSAMPLINGFREQ, 
track->sample_rate);
 put_ebml_float(mkv->tracks_bc, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, 
output_sample_rate);
-avio_seek(mkv->tracks_bc, curpos, SEEK_SET);
 } else if (!par->extradata_size && !track->sample_rate) {
 // No extradata (codecpar or packet side data).
 av_log(s, AV_LOG_ERROR, "Error parsing AAC extradata, unable to 
determine samplerate.\n");
@@ -2212,7 +2209,6 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 case AV_CODEC_ID_FLAC:
 if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && 
!mkv->is_live) {
 AVCodecParameters *codecpriv_par;
-int64_t curpos;
 if (side_data_size != par->extradata_size) {
 av_log(s, AV_LOG_ERROR, "Invalid FLAC STREAMINFO metadata for 
output stream %d\n",
pkt->stream_index);
@@ -2227,10 +2223,8 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 return ret;
 }
 memcpy(codecpriv_par->extradata, side_data, side_data_size);
-curpos = avio_tell(mkv->tracks_bc);
 avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET);
 mkv_write_codecprivate(s, mkv->tracks_bc, codecpriv_par, 1, 0);
-avio_seek(mkv->tracks_bc, curpos, SEEK_SET);
 avcodec_parameters_free(&codecpriv_par);
 }
 break;
@@ -2242,7 +2236,6 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 AVIOContext *dyn_cp;
 uint8_t *codecpriv;
 int codecpriv_size;
-int64_t curpos;
 ret = avio_open_dyn_buf(&dyn_cp);
 if (ret < 0)
 return ret;
@@ -2252,12 +2245,10 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 av_free(codecpriv);
 return AVERROR_INVALIDDATA;
 }
-curpos = avio_tell(mkv->tracks_bc);
 avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET);
 // Do not write the OBUs as we don't have space saved for them
 put_ebml_binary(mkv->tracks_bc, MATROSKA_ID_CODECPRIVATE, 
codecpriv, 4);
 av_free(codecpriv);
-avio_seek(mkv->tracks_bc, curpos, SE

[FFmpeg-cvslog] avformat/matroskaenc: Improve checks for updating Tags

2020-04-02 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Jan 22 19:37:29 2020 +0100| [af97a3a4d6b9d199654ab6328c79e6be808ce6f9] | 
committer: Andreas Rheinhardt

avformat/matroskaenc: Improve checks for updating Tags

When updating the Tags at the end, the Matroska muxer would twice check
for whether (!mkv->is_live) is true, despite this code being only executed
if it is. Furthermore, a loop iterates over all the streams even when
there is no Tags element to update at all, because the check for whether
there are Tags is only performed later. This commit fixes this.

Signed-off-by: Andreas Rheinhardt 

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

 libavformat/matroskaenc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 223406ce75..92efa98951 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2545,7 +2545,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS, 0, 
0);
 
 // update stream durations
-if (!mkv->is_live) {
+if (mkv->tags_bc) {
 int i;
 for (i = 0; i < s->nb_streams; ++i) {
 AVStream *st = s->streams[i];
@@ -2567,8 +2567,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 put_ebml_binary(mkv->tags_bc, MATROSKA_ID_TAGSTRING, 
duration_string, 20);
 }
 }
-}
-if (mkv->tags_bc && !mkv->is_live) {
+
 avio_seek(pb, mkv->tags_pos, SEEK_SET);
 end_ebml_master_crc32(pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS, 0, 
0);
 }

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

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