[FFmpeg-devel] [PATCH] bintext: use private options now that AVFormatParameters has been removed
Peter Ross
pross at xvid.org
Sat Jan 28 10:58:48 CET 2012
---
libavformat/bintext.c | 63 ++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 49 insertions(+), 14 deletions(-)
diff --git a/libavformat/bintext.c b/libavformat/bintext.c
index d9395f0..a658225 100644
--- a/libavformat/bintext.c
+++ b/libavformat/bintext.c
@@ -31,15 +31,18 @@
*/
#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
#include "avformat.h"
#include "internal.h"
#include "sauce.h"
#include "libavcodec/bintext.h"
-#define LINE_RATE 6000 /** characters per second */
-
typedef struct {
- int chars_per_frame;
+ AVClass *class;
+ int chars_per_frame; /**< Set by private option */
+ char *video_size; /**< Set by private option */
+ char *framerate; /**< Set by private option */
uint64_t fsize; /**< file size less metadata buffer */
} BinDemuxContext;
@@ -108,17 +111,30 @@ static AVStream * init_stream(AVFormatContext *s)
st->codec->codec_tag = 0;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
-// if (!ap->time_base.num) {
+ if (bin->video_size) {
+ if (av_parse_video_size(&st->codec->width, &st->codec->height, bin->video_size) < 0) {
+ av_log(s, AV_LOG_ERROR, "Could not parse video size.\n");
+ return NULL;
+ }
+ } else {
+ st->codec->width = (80<<3);
+ st->codec->height = (25<<4);
+ }
+
+ if (bin->framerate) {
+ AVRational framerate;
+ if (av_parse_video_rate(&framerate, bin->framerate) < 0) {
+ av_log(s, AV_LOG_ERROR, "Could not parse framerate.\n");
+ return NULL;
+ }
+ avpriv_set_pts_info(st, 60, framerate.den, framerate.num);
+ } else {
avpriv_set_pts_info(st, 60, 1, 25);
-// } else {
-// avpriv_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den);
-// }
+ }
/* simulate tty display speed */
- bin->chars_per_frame = FFMAX(av_q2d(st->time_base) * (/*ap->sample_rate ? ap->sample_rate :*/ LINE_RATE), 1);
+ bin->chars_per_frame = FFMAX(av_q2d(st->time_base) * bin->chars_per_frame, 1);
- st->codec->width = /*ap->width ? ap->width :*/ (80<<3);
- st->codec->height = /*ap->height ? ap->height :*/ (25<<4);
return st;
}
@@ -144,10 +160,10 @@ static int bintext_read_header(AVFormatContext *s)
bin->fsize = avio_size(pb);
if (ff_sauce_read(s, &bin->fsize, &got_width, 0) < 0)
next_tag_read(s, &bin->fsize);
-// if (!ap->width)
+ if (!bin->video_size) {
predict_width(st->codec, bin->fsize, got_width);
-// if (!ap->height)
calculate_height(st->codec, bin->fsize);
+ }
avio_seek(pb, 0, SEEK_SET);
}
return 0;
@@ -243,7 +259,7 @@ static int adf_read_header(AVFormatContext *s)
bin->fsize = avio_size(pb) - 1 - 192 - 4096;
st->codec->width = 80<<3;
ff_sauce_read(s, &bin->fsize, &got_width, 0);
-// if (!ap->height)
+ if (!bin->video_size)
calculate_height(st->codec, bin->fsize);
avio_seek(pb, 1 + 192 + 4096, SEEK_SET);
}
@@ -296,7 +312,7 @@ static int idf_read_header(AVFormatContext *s)
bin->fsize = avio_size(pb) - 12 - 4096 - 48;
ff_sauce_read(s, &bin->fsize, &got_width, 0);
-// if (!ap->height)
+ if (!bin->video_size)
calculate_height(st->codec, bin->fsize);
avio_seek(pb, 12, SEEK_SET);
return 0;
@@ -325,6 +341,21 @@ static int read_packet(AVFormatContext *s,
return 0;
}
+#define OFFSET(x) offsetof(BinDemuxContext, x)
+static const AVOption options[] = {
+ { "linespeed", "Line speed (bytes per second)", OFFSET(chars_per_frame), AV_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},
+ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
+ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
+ { NULL },
+};
+
+static const AVClass bintext_demuxer_class = {
+ .class_name = "Binary text demuxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
#if CONFIG_BINTEXT_DEMUXER
AVInputFormat ff_bintext_demuxer = {
.name = "bin",
@@ -333,6 +364,7 @@ AVInputFormat ff_bintext_demuxer = {
.read_header = bintext_read_header,
.read_packet = read_packet,
.extensions = "bin",
+ .priv_class = &bintext_demuxer_class,
};
#endif
@@ -344,6 +376,7 @@ AVInputFormat ff_xbin_demuxer = {
.read_probe = xbin_probe,
.read_header = xbin_read_header,
.read_packet = read_packet,
+ .priv_class = &bintext_demuxer_class,
};
#endif
@@ -355,6 +388,7 @@ AVInputFormat ff_adf_demuxer = {
.read_header = adf_read_header,
.read_packet = read_packet,
.extensions = "adf",
+ .priv_class = &bintext_demuxer_class,
};
#endif
@@ -367,5 +401,6 @@ AVInputFormat ff_idf_demuxer = {
.read_header = idf_read_header,
.read_packet = read_packet,
.extensions = "idf",
+ .priv_class = &bintext_demuxer_class,
};
#endif
--
1.7.5.4
-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120128/dbb1ae01/attachment.asc>
More information about the ffmpeg-devel
mailing list