annotate mvi.c @ 5950:f80cd2cf07e4 libavformat

Do not probe when the format is known. Patch by Jean-Daniel Dupas devlists shadowlab org
author benoit
date Tue, 13 Apr 2010 07:25:50 +0000
parents 536e5527c1e0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3556
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
1 /*
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
2 * Motion Pixels MVI Demuxer
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
3 * Copyright (c) 2008 Gregory Montoir (cyx@users.sourceforge.net)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
4 *
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
5 * This file is part of FFmpeg.
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
6 *
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
11 *
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
15 * Lesser General Public License for more details.
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
16 *
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
20 */
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
21
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
22 #include "avformat.h"
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
23
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
24 #define MVI_FRAC_BITS 10
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
25
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
26 #define MVI_AUDIO_STREAM_INDEX 0
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
27 #define MVI_VIDEO_STREAM_INDEX 1
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
28
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
29 typedef struct MviDemuxContext {
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
30 unsigned int (*get_int)(ByteIOContext *);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
31 uint32_t audio_data_size;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
32 uint64_t audio_size_counter;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
33 uint64_t audio_frame_size;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
34 int audio_size_left;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
35 int video_frame_size;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
36 } MviDemuxContext;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
37
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
38 static int read_header(AVFormatContext *s, AVFormatParameters *ap)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
39 {
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
40 MviDemuxContext *mvi = s->priv_data;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
41 ByteIOContext *pb = s->pb;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
42 AVStream *ast, *vst;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
43 unsigned int version, frames_count, msecs_per_frame, player_version;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
44
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
45 ast = av_new_stream(s, 0);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
46 if (!ast)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
47 return AVERROR(ENOMEM);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
48
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
49 vst = av_new_stream(s, 0);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
50 if (!vst)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
51 return AVERROR(ENOMEM);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
52
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
53 vst->codec->extradata_size = 2;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
54 vst->codec->extradata = av_mallocz(2 + FF_INPUT_BUFFER_PADDING_SIZE);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
55
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
56 version = get_byte(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
57 vst->codec->extradata[0] = get_byte(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
58 vst->codec->extradata[1] = get_byte(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
59 frames_count = get_le32(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
60 msecs_per_frame = get_le32(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
61 vst->codec->width = get_le16(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
62 vst->codec->height = get_le16(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
63 get_byte(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
64 ast->codec->sample_rate = get_le16(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
65 mvi->audio_data_size = get_le32(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
66 get_byte(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
67 player_version = get_le32(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
68 get_le16(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
69 get_byte(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
70
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
71 if (frames_count == 0 || mvi->audio_data_size == 0)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
72 return AVERROR_INVALIDDATA;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
73
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
74 if (version != 7 || player_version > 213) {
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
75 av_log(s, AV_LOG_ERROR, "unhandled version (%d,%d)\n", version, player_version);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
76 return AVERROR_INVALIDDATA;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
77 }
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
78
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
79 av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5386
diff changeset
80 ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
3556
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
81 ast->codec->codec_id = CODEC_ID_PCM_U8;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
82 ast->codec->channels = 1;
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3556
diff changeset
83 ast->codec->bits_per_coded_sample = 8;
3556
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
84 ast->codec->bit_rate = ast->codec->sample_rate * 8;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
85
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
86 av_set_pts_info(vst, 64, msecs_per_frame, 1000000);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5386
diff changeset
87 vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
3556
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
88 vst->codec->codec_id = CODEC_ID_MOTIONPIXELS;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
89
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
90 mvi->get_int = (vst->codec->width * vst->codec->height < (1 << 16)) ? get_le16 : get_le24;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
91
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
92 mvi->audio_frame_size = ((uint64_t)mvi->audio_data_size << MVI_FRAC_BITS) / frames_count;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
93 mvi->audio_size_counter = (ast->codec->sample_rate * 830 / mvi->audio_frame_size - 1) * mvi->audio_frame_size;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
94 mvi->audio_size_left = mvi->audio_data_size;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
95
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
96 return 0;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
97 }
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
98
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
99 static int read_packet(AVFormatContext *s, AVPacket *pkt)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
100 {
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
101 int ret, count;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
102 MviDemuxContext *mvi = s->priv_data;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
103 ByteIOContext *pb = s->pb;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
104
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
105 if (mvi->video_frame_size == 0) {
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
106 mvi->video_frame_size = (mvi->get_int)(pb);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
107 if (mvi->audio_size_left == 0)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
108 return AVERROR(EIO);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
109 count = (mvi->audio_size_counter + mvi->audio_frame_size + 512) >> MVI_FRAC_BITS;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
110 if (count > mvi->audio_size_left)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
111 count = mvi->audio_size_left;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
112 if ((ret = av_get_packet(pb, pkt, count)) < 0)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
113 return ret;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
114 pkt->stream_index = MVI_AUDIO_STREAM_INDEX;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
115 mvi->audio_size_left -= count;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
116 mvi->audio_size_counter += mvi->audio_frame_size - (count << MVI_FRAC_BITS);
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
117 } else {
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
118 if ((ret = av_get_packet(pb, pkt, mvi->video_frame_size)) < 0)
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
119 return ret;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
120 pkt->stream_index = MVI_VIDEO_STREAM_INDEX;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
121 mvi->video_frame_size = 0;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
122 }
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
123 return 0;
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
124 }
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
125
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
126 AVInputFormat mvi_demuxer = {
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
127 "mvi",
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
128 NULL_IF_CONFIG_SMALL("Motion Pixels MVI format"),
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
129 sizeof(MviDemuxContext),
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
130 NULL,
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
131 read_header,
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
132 read_packet,
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
133 .extensions = "mvi"
5ad678c7e341 Motion Pixels MVI Demuxer.
ramiro
parents:
diff changeset
134 };