[FFmpeg-devel] [PATCH] astenc: Add an option to set the loop flag
James Almer
jamrial at gmail.com
Sat Jan 5 16:51:01 CET 2013
On 05/01/13 12:22 PM, Michael Niedermayer wrote:
> I notice theres noone listed in MAINTAINERS for astenc.c
> maybe you want to add yourself there ?
Sure. I forgot to do it when i first submitted the file in question.
> about the change/patch
> patches need to be tested, patches need to be applied
> I assume you tested the changed code, so posting it should be a
> a few seconds work only.
> Its simply a bad idea to take patches change them according to some
> english description and then hope that this matches what someone else
> tested ...
> besides its work and we are all lazy
Since the change i mentioned was simple i didn't think it was worth sending an updated patch, sorry.
I'm attaching it then.
Regards.
-------------- next part --------------
>From 4fbf4bcc2588d5a173fa0f8dcd5ae13596abb7cc Mon Sep 17 00:00:00 2001
From: James Almer <jamrial at gmail.com>
Date: Sat, 5 Jan 2013 12:39:42 -0300
Subject: [PATCH] astenc: Enable the loop flag only when needed
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavformat/astenc.c | 36 ++++++++++++++++++++++++------------
libavformat/version.h | 2 +-
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/libavformat/astenc.c b/libavformat/astenc.c
index 10001c7..edd802c 100644
--- a/libavformat/astenc.c
+++ b/libavformat/astenc.c
@@ -36,7 +36,7 @@ typedef struct ASTMuxContext {
} ASTMuxContext;
#define CHECK_LOOP(type) \
- if (ast->loop ## type) { \
+ if (ast->loop ## type > 0) { \
ast->loop ## type = av_rescale_rnd(ast->loop ## type, enc->sample_rate, 1000, AV_ROUND_DOWN); \
if (ast->loop ## type < 0 || ast->loop ## type > UINT_MAX) { \
av_log(s, AV_LOG_ERROR, "Invalid loop" #type " value\n"); \
@@ -69,7 +69,7 @@ static int ast_write_header(AVFormatContext *s)
return AVERROR(EINVAL);
}
- if (ast->loopstart && ast->loopend && ast->loopstart >= ast->loopend) {
+ if (ast->loopend > 0 && ast->loopstart >= ast->loopend) {
av_log(s, AV_LOG_ERROR, "loopend can't be less or equal to loopstart\n");
return AVERROR(EINVAL);
}
@@ -85,7 +85,7 @@ static int ast_write_header(AVFormatContext *s)
avio_wb16(pb, codec_tag);
avio_wb16(pb, 16); /* Bit depth */
avio_wb16(pb, enc->channels);
- avio_wb16(pb, 0xFFFF);
+ avio_wb16(pb, 0); /* Loop flag */
avio_wb32(pb, enc->sample_rate);
ast->samples = avio_tell(pb);
@@ -140,23 +140,23 @@ static int ast_write_trailer(AVFormatContext *s)
av_log(s, AV_LOG_DEBUG, "total samples: %"PRId64"\n", samples);
if (s->pb->seekable) {
- /* File size minus header */
- avio_seek(pb, ast->size, SEEK_SET);
- avio_wb32(pb, file_size - 64);
-
/* Number of samples */
avio_seek(pb, ast->samples, SEEK_SET);
avio_wb32(pb, samples);
/* Loopstart if provided */
- if (ast->loopstart && ast->loopstart >= samples) {
+ if (ast->loopstart > 0) {
+ if (ast->loopstart >= samples) {
av_log(s, AV_LOG_WARNING, "Loopstart value is out of range and will be ignored\n");
- ast->loopstart = 0;
- }
+ ast->loopstart = -1;
+ avio_skip(pb, 4);
+ } else
avio_wb32(pb, ast->loopstart);
+ } else
+ avio_skip(pb, 4);
/* Loopend if provided. Otherwise number of samples again */
- if (ast->loopend) {
+ if (ast->loopend && ast->loopstart >= 0) {
if (ast->loopend > samples) {
av_log(s, AV_LOG_WARNING, "Loopend value is out of range and will be ignored\n");
ast->loopend = samples;
@@ -168,6 +168,18 @@ static int ast_write_trailer(AVFormatContext *s)
/* Size of first block */
avio_wb32(pb, ast->fbs);
+
+ /* File size minus header */
+ avio_seek(pb, ast->size, SEEK_SET);
+ avio_wb32(pb, file_size - 64);
+
+ /* Loop flag */
+ if (ast->loopstart >= 0) {
+ avio_skip(pb, 6);
+ avio_wb16(pb, 0xFFFF);
+ }
+
+ avio_seek(pb, file_size, SEEK_SET);
avio_flush(pb);
}
return 0;
@@ -175,7 +187,7 @@ static int ast_write_trailer(AVFormatContext *s)
#define OFFSET(obj) offsetof(ASTMuxContext, obj)
static const AVOption options[] = {
- { "loopstart", "Loopstart position in milliseconds.", OFFSET(loopstart), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+ { "loopstart", "Loopstart position in milliseconds.", OFFSET(loopstart), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
{ "loopend", "Loopend position in milliseconds.", OFFSET(loopend), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
{ NULL },
};
diff --git a/libavformat/version.h b/libavformat/version.h
index 3b760bb..d75f9c9 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MINOR 59
-#define LIBAVFORMAT_VERSION_MICRO 103
+#define LIBAVFORMAT_VERSION_MICRO 104
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
--
1.8.0.msysgit.0
-------------- next part --------------
>From 19ae4f7c33dd31622b100cd3222c167d7d837b3d Mon Sep 17 00:00:00 2001
From: James Almer <jamrial at gmail.com>
Date: Sat, 5 Jan 2013 12:43:52 -0300
Subject: [PATCH] MAINTAINERS: add myself as maintainer of lavf/astenc.c
Signed-off-by: James Almer <jamrial at gmail.com>
---
MAINTAINERS | 1 +
1 file changed, 1 insertion(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index ad380f8..ba5214c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -312,6 +312,7 @@ Muxers/Demuxers:
ape.c Kostya Shishkov
ass* Aurelien Jacobs
astdec.c Paul B Mahol
+ astenc.c James Almer
avi* Michael Niedermayer
avr.c Paul B Mahol
bink.c Peter Ross
--
1.8.0.msysgit.0
More information about the ffmpeg-devel
mailing list