Commit 01a39a97 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '55ddd700'

* commit '55ddd700':
  Silicon Graphics Movie demuxer

Conflicts:
	Changelog
	libavformat/mvdec.c
	libavformat/version.h

See: 6fb40779Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 0c67ef27 55ddd700
......@@ -246,8 +246,8 @@ OBJS-$(CONFIG_MPL2_DEMUXER) += mpl2dec.o subtitles.o
OBJS-$(CONFIG_MPSUB_DEMUXER) += mpsubdec.o subtitles.o
OBJS-$(CONFIG_MSNWC_TCP_DEMUXER) += msnwc_tcp.o
OBJS-$(CONFIG_MTV_DEMUXER) += mtv.o
OBJS-$(CONFIG_MVI_DEMUXER) += mvi.o
OBJS-$(CONFIG_MV_DEMUXER) += mvdec.o
OBJS-$(CONFIG_MVI_DEMUXER) += mvi.o
OBJS-$(CONFIG_MXF_DEMUXER) += mxfdec.o mxf.o
OBJS-$(CONFIG_MXF_MUXER) += mxfenc.o mxf.o audiointerleave.o
OBJS-$(CONFIG_MXG_DEMUXER) += mxg.o
......
......@@ -24,34 +24,40 @@
* Silicon Graphics Movie demuxer
*/
#include "libavutil/channel_layout.h"
#include "libavutil/eval.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/rational.h"
#include "avformat.h"
#include "internal.h"
typedef struct {
typedef struct MvContext {
int nb_video_tracks;
int nb_audio_tracks;
int eof_count; /**< number of streams that have finished */
int stream_index; /**< current stream index */
int frame[2]; /**< frame nb for current stream */
int eof_count; ///< number of streams that have finished
int stream_index; ///< current stream index
int frame[2]; ///< frame nb for current stream
int acompression; ///< compression level for audio stream
int aformat; ///< audio format
} MvContext;
#define AUDIO_FORMAT_SIGNED 401
static int mv_probe(AVProbeData *p)
{
if (AV_RB32(p->buf) == MKBETAG('M','O','V','I') && AV_RB16(p->buf + 4) < 3)
if (AV_RB32(p->buf) == MKBETAG('M', 'O', 'V', 'I') &&
AV_RB16(p->buf + 4) < 3)
return AVPROBE_SCORE_MAX;
return 0;
}
static char * var_read_string(AVIOContext *pb, int size)
static char *var_read_string(AVIOContext *pb, int size)
{
char *str = av_malloc(size + 1);
int n;
char *str = av_malloc(size + 1);
if (!str)
return NULL;
n = avio_get_str(pb, size, str, size + 1);
......@@ -63,9 +69,10 @@ static char * var_read_string(AVIOContext *pb, int size)
static int var_read_int(AVIOContext *pb, int size)
{
int v;
char * s = var_read_string(pb, size);
if (!s || sscanf(s, "%d", &v) != 1)
v = 0;
char *s = var_read_string(pb, size);
if (!s)
return 0;
v = strtol(s, NULL, 10);
av_free(s);
return v;
}
......@@ -73,9 +80,9 @@ static int var_read_int(AVIOContext *pb, int size)
static AVRational var_read_float(AVIOContext *pb, int size)
{
AVRational v;
char * s = var_read_string(pb, size);
char *s = var_read_string(pb, size);
if (!s)
return (AVRational){0, 0};
return (AVRational) { 0, 0 };
v = av_d2q(av_strtod(s, NULL), INT_MAX);
av_free(s);
return v;
......@@ -88,13 +95,15 @@ static void var_read_metadata(AVFormatContext *avctx, const char *tag, int size)
av_dict_set(&avctx->metadata, tag, value, AV_DICT_DONT_STRDUP_VAL);
}
static int set_channels(AVFormatContext *avctx, AVStream *st, int channels) {
static int set_channels(AVFormatContext *avctx, AVStream *st, int channels)
{
if (channels <= 0) {
av_log(avctx, AV_LOG_ERROR, "Channel count %d invalid\n", channels);
av_log(avctx, AV_LOG_ERROR, "Channel count %d invalid.\n", channels);
return AVERROR_INVALIDDATA;
}
st->codec->channels = channels;
st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO
: AV_CH_LAYOUT_STEREO;
return 0;
}
......@@ -102,7 +111,8 @@ static int set_channels(AVFormatContext *avctx, AVStream *st, int channels) {
* Parse global variable
* @return < 0 if unknown
*/
static int parse_global_var(AVFormatContext *avctx, AVStream *st, const char *name, int size)
static int parse_global_var(AVFormatContext *avctx, AVStream *st,
const char *name, int size)
{
MvContext *mv = avctx->priv_data;
AVIOContext *pb = avctx->pb;
......@@ -112,10 +122,11 @@ static int parse_global_var(AVFormatContext *avctx, AVStream *st, const char *na
mv->nb_audio_tracks = var_read_int(pb, size);
} else if (!strcmp(name, "COMMENT") || !strcmp(name, "TITLE")) {
var_read_metadata(avctx, name, size);
} else if (!strcmp(name, "LOOP_MODE") || !strcmp(name, "NUM_LOOPS") || !strcmp(name, "OPTIMIZED")) {
} else if (!strcmp(name, "LOOP_MODE") || !strcmp(name, "NUM_LOOPS") ||
!strcmp(name, "OPTIMIZED")) {
avio_skip(pb, size); // ignore
} else
return -1;
return AVERROR_INVALIDDATA;
return 0;
}
......@@ -124,15 +135,17 @@ static int parse_global_var(AVFormatContext *avctx, AVStream *st, const char *na
* Parse audio variable
* @return < 0 if unknown
*/
static int parse_audio_var(AVFormatContext *avctx, AVStream *st, const char *name, int size)
static int parse_audio_var(AVFormatContext *avctx, AVStream *st,
const char *name, int size)
{
MvContext *mv = avctx->priv_data;
AVIOContext *pb = avctx->pb;
if (!strcmp(name, "__DIR_COUNT")) {
st->nb_frames = var_read_int(pb, size);
} else if (!strcmp(name, "AUDIO_FORMAT")) {
st->codec->codec_id = var_read_int(pb, size);
mv->aformat = var_read_int(pb, size);
} else if (!strcmp(name, "COMPRESSION")) {
st->codec->codec_tag = var_read_int(pb, size);
mv->acompression = var_read_int(pb, size);
} else if (!strcmp(name, "DEFAULT_VOL")) {
var_read_metadata(avctx, name, size);
} else if (!strcmp(name, "NUM_CHANNELS")) {
......@@ -143,7 +156,8 @@ static int parse_audio_var(AVFormatContext *avctx, AVStream *st, const char *nam
} else if (!strcmp(name, "SAMPLE_WIDTH")) {
st->codec->bits_per_coded_sample = var_read_int(pb, size) * 8;
} else
return -1;
return AVERROR_INVALIDDATA;
return 0;
}
......@@ -151,13 +165,14 @@ static int parse_audio_var(AVFormatContext *avctx, AVStream *st, const char *nam
* Parse video variable
* @return < 0 if unknown
*/
static int parse_video_var(AVFormatContext *avctx, AVStream *st, const char *name, int size)
static int parse_video_var(AVFormatContext *avctx, AVStream *st,
const char *name, int size)
{
AVIOContext *pb = avctx->pb;
if (!strcmp(name, "__DIR_COUNT")) {
st->nb_frames = st->duration = var_read_int(pb, size);
} else if (!strcmp(name, "COMPRESSION")) {
char * str = var_read_string(pb, size);
char *str = var_read_string(pb, size);
if (!str)
return AVERROR_INVALIDDATA;
if (!strcmp(str, "1")) {
......@@ -172,18 +187,20 @@ static int parse_video_var(AVFormatContext *avctx, AVStream *st, const char *nam
} else if (!strcmp(str, "MVC2")) {
st->codec->codec_id = AV_CODEC_ID_MVC2;
} else {
avpriv_request_sample(avctx, "video compression %s", str);
avpriv_request_sample(avctx, "Video compression %s", str);
}
av_free(str);
} else if (!strcmp(name, "FPS")) {
AVRational fps = var_read_float(pb, size);
avpriv_set_pts_info(st, 64, fps.den, fps.num);
st->avg_frame_rate = fps;
} else if (!strcmp(name, "HEIGHT")) {
st->codec->height = var_read_int(pb, size);
} else if (!strcmp(name, "PIXEL_ASPECT")) {
st->sample_aspect_ratio = var_read_float(pb, size);
av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den,
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, INT_MAX);
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
INT_MAX);
} else if (!strcmp(name, "WIDTH")) {
st->codec->width = var_read_int(pb, size);
} else if (!strcmp(name, "ORIENTATION")) {
......@@ -196,11 +213,14 @@ static int parse_video_var(AVFormatContext *avctx, AVStream *st, const char *nam
} else if (!strcmp(name, "INTERLACING") || !strcmp(name, "PACKING")) {
avio_skip(pb, size); // ignore
} else
return -1;
return AVERROR_INVALIDDATA;
return 0;
}
static void read_table(AVFormatContext *avctx, AVStream *st, int (*parse)(AVFormatContext *avctx, AVStream *st, const char *name, int size))
static void read_table(AVFormatContext *avctx, AVStream *st,
int (*parse)(AVFormatContext *avctx, AVStream *st,
const char *name, int size))
{
int count, i;
AVIOContext *pb = avctx->pb;
......@@ -214,7 +234,7 @@ static void read_table(AVFormatContext *avctx, AVStream *st, int (*parse)(AVForm
name[sizeof(name) - 1] = 0;
size = avio_rb32(pb);
if (parse(avctx, st, name, size) < 0) {
avpriv_request_sample(avctx, "variable %s", name);
avpriv_request_sample(avctx, "Variable %s", name);
avio_skip(pb, size);
}
}
......@@ -253,7 +273,7 @@ static int mv_read_header(AVFormatContext *avctx)
avio_skip(pb, 22);
/* allocate audio track first to prevent unnecessary seeking
(audio packet always precede video packet for a given frame) */
* (audio packet always precede video packet for a given frame) */
ast = avformat_new_stream(avctx, NULL);
if (!ast)
return AVERROR(ENOMEM);
......@@ -261,8 +281,9 @@ static int mv_read_header(AVFormatContext *avctx)
vst = avformat_new_stream(avctx, NULL);
if (!vst)
return AVERROR(ENOMEM);
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
avpriv_set_pts_info(vst, 64, 1, 15);
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
vst->avg_frame_rate = av_inv_q(vst->time_base);
vst->nb_frames = avio_rb32(pb);
v = avio_rb32(pb);
switch (v) {
......@@ -274,7 +295,7 @@ static int mv_read_header(AVFormatContext *avctx)
vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
break;
default:
avpriv_request_sample(avctx, "video compression %i", v);
avpriv_request_sample(avctx, "Video compression %i", v);
break;
}
vst->codec->codec_tag = 0;
......@@ -293,7 +314,7 @@ static int mv_read_header(AVFormatContext *avctx)
if (v == AUDIO_FORMAT_SIGNED) {
ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
} else {
avpriv_request_sample(avctx, "audio compression (format %i)", v);
avpriv_request_sample(avctx, "Audio compression (format %i)", v);
}
avio_skip(pb, 12);
......@@ -317,31 +338,33 @@ static int mv_read_header(AVFormatContext *avctx)
read_table(avctx, NULL, parse_global_var);
if (mv->nb_audio_tracks > 1) {
avpriv_request_sample(avctx, "multiple audio streams support");
avpriv_request_sample(avctx, "Multiple audio streams support");
return AVERROR_PATCHWELCOME;
} else if (mv->nb_audio_tracks) {
ast = avformat_new_stream(avctx, NULL);
if (!ast)
return AVERROR(ENOMEM);
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
/* temporarily store compression value in codec_tag; format value in codec_id */
read_table(avctx, ast, parse_audio_var);
if (ast->codec->codec_tag == 100 && ast->codec->codec_id == AUDIO_FORMAT_SIGNED && ast->codec->bits_per_coded_sample == 16) {
if (mv->acompression == 100 &&
mv->aformat == AUDIO_FORMAT_SIGNED &&
ast->codec->bits_per_coded_sample == 16) {
ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
} else {
avpriv_request_sample(avctx, "audio compression %i (format %i, width %i)",
ast->codec->codec_tag, ast->codec->codec_id, ast->codec->bits_per_coded_sample);
avpriv_request_sample(avctx,
"Audio compression %i (format %i, sr %i)",
mv->acompression, mv->aformat,
ast->codec->bits_per_coded_sample);
ast->codec->codec_id = AV_CODEC_ID_NONE;
}
ast->codec->codec_tag = 0;
if (ast->codec->channels <= 0) {
av_log(avctx, AV_LOG_ERROR, "No valid channel count found\n");
av_log(avctx, AV_LOG_ERROR, "No valid channel count found.\n");
return AVERROR_INVALIDDATA;
}
}
if (mv->nb_video_tracks > 1) {
avpriv_request_sample(avctx, "multiple video streams support");
avpriv_request_sample(avctx, "Multiple video streams support");
return AVERROR_PATCHWELCOME;
} else if (mv->nb_video_tracks) {
vst = avformat_new_stream(avctx, NULL);
......@@ -357,7 +380,7 @@ static int mv_read_header(AVFormatContext *avctx)
if (mv->nb_video_tracks)
read_index(pb, vst);
} else {
avpriv_request_sample(avctx, "version %i", version);
avpriv_request_sample(avctx, "Version %i", version);
return AVERROR_PATCHWELCOME;
}
......@@ -400,6 +423,9 @@ static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)
mv->eof_count++;
if (mv->eof_count >= avctx->nb_streams)
return AVERROR_EOF;
// avoid returning 0 without a packet
return AVERROR(EAGAIN);
}
mv->stream_index++;
......@@ -409,7 +435,8 @@ static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)
return 0;
}
static int mv_read_seek(AVFormatContext *avctx, int stream_index, int64_t timestamp, int flags)
static int mv_read_seek(AVFormatContext *avctx, int stream_index,
int64_t timestamp, int flags)
{
MvContext *mv = avctx->priv_data;
AVStream *st = avctx->streams[stream_index];
......@@ -423,7 +450,7 @@ static int mv_read_seek(AVFormatContext *avctx, int stream_index, int64_t timest
frame = av_index_search_timestamp(st, timestamp, flags);
if (frame < 0)
return -1;
return AVERROR_INVALIDDATA;
for (i = 0; i < avctx->nb_streams; i++)
mv->frame[i] = frame;
......
......@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 55
#define LIBAVFORMAT_VERSION_MINOR 37
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment