[FFmpeg-cvslog] lavd/opengl_enc: use proper context for logging.

2020-02-20 Thread Nicolas George
ffmpeg | branch: master | Nicolas George  | Mon Feb 17 
12:58:35 2020 +0100| [fbb36d74ac6c491cdde552863981a593059e94b7] | committer: 
Nicolas George

lavd/opengl_enc: use proper context for logging.

Log as [opengl @ 0xaddress] instead of [opengl outdev @ 0xaddress].

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

 libavdevice/opengl_enc.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index fd0bb177d9..fa94345a7c 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -568,8 +568,9 @@ static void opengl_make_ortho(float matrix[16], float left, 
float right,
 matrix[15] = 1.0f;
 }
 
-static av_cold int opengl_read_limits(OpenGLContext *opengl)
+static av_cold int opengl_read_limits(AVFormatContext *h)
 {
+OpenGLContext *opengl = h->priv_data;
 static const struct{
 const char *extension;
 int major;
@@ -588,16 +589,16 @@ static av_cold int opengl_read_limits(OpenGLContext 
*opengl)
 version = glGetString(GL_VERSION);
 extensions = glGetString(GL_EXTENSIONS);
 
-av_log(opengl, AV_LOG_DEBUG, "OpenGL version: %s\n", version);
+av_log(h, AV_LOG_DEBUG, "OpenGL version: %s\n", version);
 sscanf(version, "%d.%d", &major, &minor);
 
 for (i = 0; required_extensions[i].extension; i++) {
 if (major < required_extensions[i].major &&
 (major == required_extensions[i].major && minor < 
required_extensions[i].minor) &&
 !strstr(extensions, required_extensions[i].extension)) {
-av_log(opengl, AV_LOG_ERROR, "Required extension %s is not 
supported.\n",
+av_log(h, AV_LOG_ERROR, "Required extension %s is not 
supported.\n",
required_extensions[i].extension);
-av_log(opengl, AV_LOG_DEBUG, "Supported extensions are: %s\n", 
extensions);
+av_log(h, AV_LOG_DEBUG, "Supported extensions are: %s\n", 
extensions);
 return AVERROR(ENOSYS);
 }
 }
@@ -610,10 +611,10 @@ static av_cold int opengl_read_limits(OpenGLContext 
*opengl)
 opengl->unpack_subimage = 1;
 #endif
 
-av_log(opengl, AV_LOG_DEBUG, "Non Power of 2 textures support: %s\n", 
opengl->non_pow_2_textures ? "Yes" : "No");
-av_log(opengl, AV_LOG_DEBUG, "Unpack Subimage extension support: %s\n", 
opengl->unpack_subimage ? "Yes" : "No");
-av_log(opengl, AV_LOG_DEBUG, "Max texture size: %dx%d\n", 
opengl->max_texture_size, opengl->max_texture_size);
-av_log(opengl, AV_LOG_DEBUG, "Max viewport size: %dx%d\n",
+av_log(h, AV_LOG_DEBUG, "Non Power of 2 textures support: %s\n", 
opengl->non_pow_2_textures ? "Yes" : "No");
+av_log(h, AV_LOG_DEBUG, "Unpack Subimage extension support: %s\n", 
opengl->unpack_subimage ? "Yes" : "No");
+av_log(h, AV_LOG_DEBUG, "Max texture size: %dx%d\n", 
opengl->max_texture_size, opengl->max_texture_size);
+av_log(h, AV_LOG_DEBUG, "Max viewport size: %dx%d\n",
opengl->max_viewport_width, opengl->max_viewport_height);
 
 OPENGL_ERROR_CHECK(opengl);
@@ -1074,7 +1075,7 @@ static av_cold int opengl_write_header(AVFormatContext *h)
 if ((ret = opengl_create_window(h)))
 goto fail;
 
-if ((ret = opengl_read_limits(opengl)) < 0)
+if ((ret = opengl_read_limits(h)) < 0)
 goto fail;
 
 if (opengl->width > opengl->max_texture_size || opengl->height > 
opengl->max_texture_size) {

___
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] lavd/opengl_enc: check strings before parsing them.

2020-02-20 Thread Nicolas George
ffmpeg | branch: master | Nicolas George  | Mon Feb 17 
12:59:27 2020 +0100| [26ae9c9f8aebbf4b925649f971f90c0dee047aa9] | committer: 
Nicolas George

lavd/opengl_enc: check strings before parsing them.

Fix a segfault if OpenGL was not initialized before calling
write_header().

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

 libavdevice/opengl_enc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index fa94345a7c..b07f9c2e43 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -588,6 +588,10 @@ static av_cold int opengl_read_limits(AVFormatContext *h)
 
 version = glGetString(GL_VERSION);
 extensions = glGetString(GL_EXTENSIONS);
+if (!version || !extensions) {
+av_log(h, AV_LOG_ERROR, "No OpenGL context initialized for the current 
thread\n");
+return AVERROR(ENOSYS);
+}
 
 av_log(h, AV_LOG_DEBUG, "OpenGL version: %s\n", version);
 sscanf(version, "%d.%d", &major, &minor);

___
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/vivo: set packet duration

2020-02-20 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Wed Apr  4 20:23:23 
2018 +0200| [a07b19d9af6377beac5630cb49065ede426c4fee] | committer: Paul B Mahol

avformat/vivo: set packet duration

Signed-off-by: Paul B Mahol 

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

 libavformat/vivo.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/vivo.c b/libavformat/vivo.c
index 2defda992b..fb58aa6178 100644
--- a/libavformat/vivo.c
+++ b/libavformat/vivo.c
@@ -36,6 +36,7 @@ typedef struct VivoContext {
 int type;
 int sequence;
 int length;
+int duration;
 
 uint8_t  text[1024 + 1];
 } VivoContext;
@@ -237,6 +238,7 @@ static int vivo_read_header(AVFormatContext *s)
 ast->codecpar->bits_per_coded_sample = 16;
 ast->codecpar->block_align = 40;
 ast->codecpar->bit_rate = 6400;
+vivo->duration = 320;
 }
 
 ast->start_time= 0;
@@ -252,7 +254,7 @@ static int vivo_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 VivoContext *vivo = s->priv_data;
 AVIOContext *pb = s->pb;
 unsigned old_sequence = vivo->sequence, old_type = vivo->type;
-int stream_index, ret = 0;
+int stream_index, duration, ret = 0;
 
 restart:
 
@@ -268,10 +270,12 @@ restart:
 case 1:
 case 2: // video
 stream_index = 0;
+duration = 1;
 break;
 case 3:
 case 4: // audio
 stream_index = 1;
+duration = vivo->duration;
 break;
 default:
 av_log(s, AV_LOG_ERROR, "unknown packet type %d\n", vivo->type);
@@ -300,6 +304,7 @@ restart:
 }
 
 pkt->stream_index = stream_index;
+pkt->duration = duration;
 
 return ret;
 }

___
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/vivo: improve probing of some files

2020-02-20 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Wed Apr  4 11:47:42 
2018 +0200| [b4305d60f68ade2601dbf238ae5a88d74d388f98] | committer: Paul B Mahol

avformat/vivo: improve probing of some files

Signed-off-by: Paul B Mahol 

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

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

diff --git a/libavformat/vivo.c b/libavformat/vivo.c
index 7f30a3f031..2defda992b 100644
--- a/libavformat/vivo.c
+++ b/libavformat/vivo.c
@@ -59,9 +59,10 @@ static int vivo_probe(const AVProbeData *p)
 if (c & 0x80 || length > 1024 || length < 21)
 return 0;
 
-if (memcmp(buf, "\r\nVersion:Vivo/", 15))
+buf += 2;
+if (memcmp(buf, "Version:Vivo/", 13))
 return 0;
-buf += 15;
+buf += 13;
 
 if (*buf < '0' || *buf > '2')
 return 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".

[FFmpeg-cvslog] avcodec: add siren audio decoder

2020-02-20 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Tue Apr  3 21:49:48 
2018 +0200| [464310c16062efe234cb016ff41fa312546dfc5e] | committer: Paul B Mahol

avcodec: add siren audio decoder

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

 Changelog   |   1 +
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/avcodec.h|   1 +
 libavcodec/codec_desc.c |   7 +
 libavcodec/siren.c  | 773 
 libavcodec/version.h|   2 +-
 libavformat/vivo.c  |   5 +
 8 files changed, 790 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index c18e7b9c3d..d8b8bd0afe 100644
--- a/Changelog
+++ b/Changelog
@@ -37,6 +37,7 @@ version :
 - afirsrc audio filter source
 - pad_opencl filter
 - CDToons video decoder
+- siren audio decoder
 
 
 version 4.2:
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 71eeb60901..a6227ced26 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -584,6 +584,7 @@ OBJS-$(CONFIG_SIPR_DECODER)+= sipr.o 
acelp_pitch_delay.o \
   celp_math.o acelp_vectors.o \
   acelp_filters.o celp_filters.o \
   sipr16k.o
+OBJS-$(CONFIG_SIREN_DECODER)   += siren.o
 OBJS-$(CONFIG_SMACKAUD_DECODER)+= smacker.o
 OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o
 OBJS-$(CONFIG_SMC_DECODER) += smc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 103f34fd32..94e196202a 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -474,6 +474,7 @@ extern AVCodec ff_sbc_encoder;
 extern AVCodec ff_sbc_decoder;
 extern AVCodec ff_shorten_decoder;
 extern AVCodec ff_sipr_decoder;
+extern AVCodec ff_siren_decoder;
 extern AVCodec ff_smackaud_decoder;
 extern AVCodec ff_sonic_encoder;
 extern AVCodec ff_sonic_decoder;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 368341ba93..978f36d12a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -661,6 +661,7 @@ enum AVCodecID {
 AV_CODEC_ID_HCOM,
 AV_CODEC_ID_ACELP_KELVIN,
 AV_CODEC_ID_MPEGH_3D_AUDIO,
+AV_CODEC_ID_SIREN,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 609c7501fd..89bdfa3fce 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3044,6 +3044,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("MPEG-H 3D Audio"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_SIREN,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "siren",
+.long_name = NULL_IF_CONFIG_SMALL("Siren"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/siren.c b/libavcodec/siren.c
new file mode 100644
index 00..2577ff52dd
--- /dev/null
+++ b/libavcodec/siren.c
@@ -0,0 +1,773 @@
+/*
+ * Siren audio decoder
+ * Copyright (c) 2012 Youness Alaoui 
+ * Copyright (c) 2018 Paul B Mahol
+ * Copyright (c) 2019 Lynne 
+ *
+ * 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/tx.h"
+#include "libavutil/float_dsp.h"
+
+#include "avcodec.h"
+#include "get_bits.h"
+#include "internal.h"
+#include "mathops.h"
+
+static const uint8_t index_table[8] = {4, 4, 3, 3, 2, 2, 1, 0};
+static const uint8_t vector_dimension[8] = { 2, 2, 2, 4, 4, 5, 5, 1 };
+static const uint8_t number_of_vectors[8] = { 10, 10, 10, 5, 5, 4, 4, 20 };
+static const uint8_t expected_bits_table[8] = { 52, 47, 43, 37, 29, 22, 16, 0 
};
+static const int8_t differential_decoder_tree[27][24][2] = {
+{
+{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, -12}, {-11, -10}, {-8, 
-9}, {-7, -6}, {-13, 12},
+{-5, -4}, {0, 13}, {-3, -14}, {-2, 14}, {-1, 15}, {-15, 16}, {-16, 
17}, {-17, 18}, {19, 20},
+{21, 22}, {-18, -19}, {-20, -21}, {-22, -23}, {-32, -32}
+},
+{
+{1, 2}, {3, 4}, {5, 6}, {7, 8}, {-10, -9}, {

[FFmpeg-cvslog] avformat/spdifenc: make hd_buf an array

2020-02-20 Thread Anssi Hannula
ffmpeg | branch: master | Anssi Hannula  | Thu Feb 20 
21:49:50 2020 +0200| [1d5338e450b18c5715271dee48761e2438d3bd77] | committer: 
Anssi Hannula

avformat/spdifenc: make hd_buf an array

This is preparation for adding a second hd_buf in a followup commit.

Also, slightly improve the comments for hd_buf_x members to clarify
which ones are actually used and kept up-to-date depending on which
codec is being muxed.

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

 libavformat/spdifenc.c | 48 
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index d5f7d91e93..6b6b1dd3b1 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -69,10 +69,10 @@ typedef struct IEC61937Context {
 int use_preamble;   ///< preamble enabled (disabled for 
exactly pre-padded DTS)
 int extra_bswap;///< extra bswap for payload (for LE DTS 
=> standard BE DTS)
 
-uint8_t *hd_buf;///< allocated buffer to concatenate hd 
audio frames
-int hd_buf_size;///< size of the hd audio buffer
-int hd_buf_count;   ///< number of frames in the hd audio 
buffer
-int hd_buf_filled;  ///< amount of bytes in the hd audio buffer
+uint8_t *hd_buf[1]; ///< allocated buffer to concatenate hd 
audio frames
+int hd_buf_size;///< size of the hd audio buffer (eac3, 
dts4)
+int hd_buf_count;   ///< number of frames in the hd audio 
buffer (eac3, truehd)
+int hd_buf_filled;  ///< amount of bytes in the hd audio 
buffer (eac3)
 
 int dtshd_skip; ///< counter used for skipping DTS-HD 
frames
 
@@ -122,11 +122,11 @@ static int spdif_header_eac3(AVFormatContext *s, AVPacket 
*pkt)
 if (bsid > 10 && (pkt->data[4] & 0xc0) != 0xc0) /* fscod */
 repeat = eac3_repeat[(pkt->data[4] & 0x30) >> 4]; /* numblkscod */
 
-ctx->hd_buf = av_fast_realloc(ctx->hd_buf, &ctx->hd_buf_size, 
ctx->hd_buf_filled + pkt->size);
-if (!ctx->hd_buf)
+ctx->hd_buf[0] = av_fast_realloc(ctx->hd_buf[0], &ctx->hd_buf_size, 
ctx->hd_buf_filled + pkt->size);
+if (!ctx->hd_buf[0])
 return AVERROR(ENOMEM);
 
-memcpy(&ctx->hd_buf[ctx->hd_buf_filled], pkt->data, pkt->size);
+memcpy(&ctx->hd_buf[0][ctx->hd_buf_filled], pkt->data, pkt->size);
 
 ctx->hd_buf_filled += pkt->size;
 if (++ctx->hd_buf_count < repeat){
@@ -135,7 +135,7 @@ static int spdif_header_eac3(AVFormatContext *s, AVPacket 
*pkt)
 }
 ctx->data_type   = IEC61937_EAC3;
 ctx->pkt_offset  = 24576;
-ctx->out_buf = ctx->hd_buf;
+ctx->out_buf = ctx->hd_buf[0];
 ctx->out_bytes   = ctx->hd_buf_filled;
 ctx->length_code = ctx->hd_buf_filled;
 
@@ -228,15 +228,15 @@ static int spdif_header_dts4(AVFormatContext *s, AVPacket 
*pkt, int core_size,
  * with some receivers, but the exact requirement is unconfirmed. */
 ctx->length_code = FFALIGN(ctx->out_bytes + 0x8, 0x10) - 0x8;
 
-av_fast_malloc(&ctx->hd_buf, &ctx->hd_buf_size, ctx->out_bytes);
-if (!ctx->hd_buf)
+av_fast_malloc(&ctx->hd_buf[0], &ctx->hd_buf_size, ctx->out_bytes);
+if (!ctx->hd_buf[0])
 return AVERROR(ENOMEM);
 
-ctx->out_buf = ctx->hd_buf;
+ctx->out_buf = ctx->hd_buf[0];
 
-memcpy(ctx->hd_buf, dtshd_start_code, sizeof(dtshd_start_code));
-AV_WB16(ctx->hd_buf + sizeof(dtshd_start_code), pkt_size);
-memcpy(ctx->hd_buf + sizeof(dtshd_start_code) + 2, pkt->data, pkt_size);
+memcpy(ctx->hd_buf[0], dtshd_start_code, sizeof(dtshd_start_code));
+AV_WB16(ctx->hd_buf[0] + sizeof(dtshd_start_code), pkt_size);
+memcpy(ctx->hd_buf[0] + sizeof(dtshd_start_code) + 2, pkt->data, pkt_size);
 
 return 0;
 }
@@ -403,12 +403,12 @@ static int spdif_header_truehd(AVFormatContext *s, 
AVPacket *pkt)
 if (!ctx->hd_buf_count) {
 static const char mat_start_code[20] = { 0x07, 0x9E, 0x00, 0x03, 0x84, 
0x01, 0x01, 0x01, 0x80, 0x00, 0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83, 0x49, 0x80, 
0x77, 0xE0 };
 mat_code_length = sizeof(mat_start_code) + BURST_HEADER_SIZE;
-memcpy(ctx->hd_buf, mat_start_code, sizeof(mat_start_code));
+memcpy(ctx->hd_buf[0], mat_start_code, sizeof(mat_start_code));
 
 } else if (ctx->hd_buf_count == 12) {
 static const char mat_middle_code[12] = { 0xC3, 0xC1, 0x42, 0x49, 
0x3B, 0xFA, 0x82, 0x83, 0x49, 0x80, 0x77, 0xE0 };
 mat_code_length = sizeof(mat_middle_code) + MAT_MIDDLE_CODE_OFFSET;
-memcpy(&ctx->hd_buf[12 * TRUEHD_FRAME_OFFSET - BURST_HEADER_SIZE + 
MAT_MIDDLE_CODE_OFFSET],
+memcpy(&ctx->hd_buf[0][12 * TRUEHD_FRAME_OFFSET - BURST_HEADER_SIZE + 
MAT_MIDDLE_CODE_OFFSET],
mat_middle_code, sizeof(mat_middle_code));
 }
 
@@ -420,26 +420,26 @@ static int spdif_header_truehd(AVFormatCont

[FFmpeg-cvslog] avformat/spdifenc: fix handling of large TrueHD frames

2020-02-20 Thread Anssi Hannula
ffmpeg | branch: master | Anssi Hannula  | Wed Feb 19 
22:46:35 2020 +0200| [36e156bef02566d70cea46cc5e00b3e5d5ed3286] | committer: 
Anssi Hannula

avformat/spdifenc: fix handling of large TrueHD frames

The TrueHD IEC 61937 encapsulation code uses a very naive method of
always inserting 24 TrueHD frames evenly in a MAT frame. This does not
work for larger frames as they may exceed the size of 1/24th of a MAT
frame.

To fix that, use the input_timing field in the TrueHD frame to determine
the proper position of the TrueHD frame in the MAT frame. That field is
basically a dts field, telling the time to feed this frame to the
decoder in sample count units.

This can cause a TrueHD frame to be split between two MAT frames, so a
second concatenation hd_buf is added, alternating with the first buffer.

Large frames are preceded by smaller frames that have input_timing
values that cause the frames to be sent out faster than the nominal rate
(i.e. increasing decoder latency, long decoder buffer), allowing the
larger frames to then be sent out slower than the nominal rate as the
decoder has enough data buffered to keep it busy.

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

 libavformat/spdifenc.c | 215 ++---
 1 file changed, 168 insertions(+), 47 deletions(-)

diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index 6b6b1dd3b1..dcfab87cc4 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -1,7 +1,7 @@
 /*
  * IEC 61937 muxer
  * Copyright (c) 2009 Bartlomiej Wolowiec
- * Copyright (c) 2010 Anssi Hannula
+ * Copyright (c) 2010, 2020 Anssi Hannula
  * Copyright (c) 2010 Carl Eugen Hoyos
  *
  * This file is part of FFmpeg.
@@ -69,13 +69,18 @@ typedef struct IEC61937Context {
 int use_preamble;   ///< preamble enabled (disabled for 
exactly pre-padded DTS)
 int extra_bswap;///< extra bswap for payload (for LE DTS 
=> standard BE DTS)
 
-uint8_t *hd_buf[1]; ///< allocated buffer to concatenate hd 
audio frames
+uint8_t *hd_buf[2]; ///< allocated buffers to concatenate hd 
audio frames
 int hd_buf_size;///< size of the hd audio buffer (eac3, 
dts4)
-int hd_buf_count;   ///< number of frames in the hd audio 
buffer (eac3, truehd)
-int hd_buf_filled;  ///< amount of bytes in the hd audio 
buffer (eac3)
+int hd_buf_count;   ///< number of frames in the hd audio 
buffer (eac3)
+int hd_buf_filled;  ///< amount of bytes in the hd audio 
buffer (eac3, truehd)
+int hd_buf_idx; ///< active hd buffer index (truehd)
 
 int dtshd_skip; ///< counter used for skipping DTS-HD 
frames
 
+uint16_t truehd_prev_time;  ///< input_timing from the last frame
+int truehd_prev_size;   ///< previous frame size in bytes, 
including any MAT codes
+int truehd_samples_per_frame;   ///< samples per frame for padding 
calculation
+
 /* AVOptions: */
 int dtshd_rate;
 int dtshd_fallback;
@@ -384,62 +389,175 @@ static int spdif_header_aac(AVFormatContext *s, AVPacket 
*pkt)
 /*
  * It seems Dolby TrueHD frames have to be encapsulated in MAT frames before
  * they can be encapsulated in IEC 61937.
- * Here we encapsulate 24 TrueHD frames in a single MAT frame, padding them
- * to achieve constant rate.
- * The actual format of a MAT frame is unknown, but the below seems to work.
- * However, it seems it is not actually necessary for the 24 TrueHD frames to
- * be in an exact alignment with the MAT frame.
  */
+#define MAT_PKT_OFFSET  61440
 #define MAT_FRAME_SIZE  61424
-#define TRUEHD_FRAME_OFFSET 2560
-#define MAT_MIDDLE_CODE_OFFSET  -4
+
+static const uint8_t mat_start_code[20] = {
+0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00, 0x56, 0xA5, 
0x3B, 0xF4, 0x81, 0x83,
+0x49, 0x80, 0x77, 0xE0,
+};
+static const uint8_t mat_middle_code[12] = {
+0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA, 0x82, 0x83, 0x49, 0x80, 0x77, 0xE0,
+};
+static const uint8_t mat_end_code[16] = {
+0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x97, 0x11,
+};
+
+#define MAT_CODE(position, data) { .pos = position, .code = data, .len = 
sizeof(data) }
+
+static const struct {
+unsigned int pos;
+const uint8_t *code;
+unsigned int len;
+} mat_codes[] = {
+MAT_CODE(0, mat_start_code),
+MAT_CODE(30708, mat_middle_code),
+MAT_CODE(MAT_FRAME_SIZE - sizeof(mat_end_code), mat_end_code),
+};
 
 static int spdif_header_truehd(AVFormatContext *s, AVPacket *pkt)
 {
 IEC61937Context *ctx = s->priv_data;
-int mat_code_length = 0;
-static const char mat_end_code[16] = { 0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11 };
-
-if (!ctx->hd_buf_count) {
-static const char mat_s

[FFmpeg-cvslog] avformat/spdifenc: fix TrueHD streams over 48kHz

2020-02-20 Thread Anssi Hannula
ffmpeg | branch: master | Anssi Hannula  | Thu Feb 20 
23:04:50 2020 +0200| [56df8296f5221524bd06e91e6639c08753d1b8a0] | committer: 
Anssi Hannula

avformat/spdifenc: fix TrueHD streams over 48kHz

Commit 36e156bef02 ("avformat/spdifenc: fix handling of large TrueHD
frame") added an obviously incorrect bitshift that caused incorrect
samples-per-frame calculation for TrueHD streams over 48kHz.

Fix that.

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

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

diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c
index dcfab87cc4..0288872fd3 100644
--- a/libavformat/spdifenc.c
+++ b/libavformat/spdifenc.c
@@ -435,9 +435,9 @@ static int spdif_header_truehd(AVFormatContext *s, AVPacket 
*pkt)
 if (AV_RB24(pkt->data + 4) == 0xf8726f) {
 /* major sync unit, fetch sample rate */
 if (pkt->data[7] == 0xba)
-ratebits = pkt->data[8] >> 8;
+ratebits = pkt->data[8] >> 4;
 else if (pkt->data[7] == 0xbb)
-ratebits = pkt->data[9] >> 8;
+ratebits = pkt->data[9] >> 4;
 else
 return AVERROR_INVALIDDATA;
 

___
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".