annotate lmlm4.c @ 3806:fa043e93fc66 libavformat

introduce mxf_write_local_tag_utf16 and factorize
author bcoudurier
date Sat, 30 Aug 2008 22:32:23 +0000
parents 7a0230981402
children 7d2f3f1b68d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2911
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
1 /*
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
2 * Linux Media Labs MPEG-4 demuxer
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
3 * Copyright (c) 2008 Ivo van Poorten
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
4 *
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
5 * Due to a lack of sample files, only files with one channel are supported.
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
6 * u-law and ADPCM audio are unsupported for the same reason.
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
7 *
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
8 * This file is part of FFmpeg.
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
9 *
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
10 * FFmpeg is free software; you can redistribute it and/or
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
11 * modify it under the terms of the GNU Lesser General Public
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
12 * License as published by the Free Software Foundation; either
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
13 * version 2.1 of the License, or (at your option) any later version.
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
14 *
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
15 * FFmpeg is distributed in the hope that it will be useful,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
18 * Lesser General Public License for more details.
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
19 *
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
20 * You should have received a copy of the GNU Lesser General Public
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
21 * License along with FFmpeg; if not, write to the Free Software
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
23 */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
24
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
25 #include "avformat.h"
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
26
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
27 #define LMLM4_I_FRAME 0x00
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
28 #define LMLM4_P_FRAME 0x01
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
29 #define LMLM4_B_FRAME 0x02
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
30 #define LMLM4_INVALID 0x03
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
31 #define LMLM4_MPEG1L2 0x04
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
32
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
33 #define LMLM4_MAX_PACKET_SIZE 1024 * 1024
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
34
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
35 static int lmlm4_probe(AVProbeData * pd) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
36 unsigned char *buf = pd->buf;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
37 unsigned int frame_type, packet_size;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
38
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
39 frame_type = AV_RB16(buf+2);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
40 packet_size = AV_RB32(buf+4);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
41
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
42 if (!AV_RB16(buf) && frame_type <= LMLM4_MPEG1L2 && packet_size &&
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
43 frame_type != LMLM4_INVALID && packet_size <= LMLM4_MAX_PACKET_SIZE) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
44
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
45 if (frame_type == LMLM4_MPEG1L2) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
46 if ((AV_RB16(buf+8) & 0xfffe) != 0xfffc)
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
47 return 0;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
48 /* I could calculate the audio framesize and compare with
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
49 * packet_size-8, but that seems overkill */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
50 return AVPROBE_SCORE_MAX / 3;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
51 } else if (AV_RB24(buf+8) == 0x000001) { /* PES Signal */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
52 return AVPROBE_SCORE_MAX / 5;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
53 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
54 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
55
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
56 return 0;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
57 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
58
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
59 static int lmlm4_read_header(AVFormatContext *s, AVFormatParameters *ap) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
60 AVStream *st;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
61
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
62 if (!(st = av_new_stream(s, 0)))
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
63 return AVERROR(ENOMEM);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
64 st->codec->codec_type = CODEC_TYPE_VIDEO;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
65 st->codec->codec_id = CODEC_ID_MPEG4;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
66 st->need_parsing = AVSTREAM_PARSE_HEADERS;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
67 av_set_pts_info(st, 64, 1001, 30000);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
68
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
69 if (!(st = av_new_stream(s, 1)))
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
70 return AVERROR(ENOMEM);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
71 st->codec->codec_type = CODEC_TYPE_AUDIO;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
72 st->codec->codec_id = CODEC_ID_MP2;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
73 st->need_parsing = AVSTREAM_PARSE_HEADERS;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
74
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
75 /* the parameters will be extracted from the compressed bitstream */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
76 return 0;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
77 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
78
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
79 static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
80 ByteIOContext *pb = s->pb;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
81 int ret;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
82 unsigned int frame_type, packet_size, padding, frame_size;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
83
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
84 get_be16(pb); /* channel number */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
85 frame_type = get_be16(pb);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
86 packet_size = get_be32(pb);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
87 padding = -packet_size & 511;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
88 frame_size = packet_size - 8;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
89
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
90 if (frame_type > LMLM4_MPEG1L2 || frame_type == LMLM4_INVALID) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
91 av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n");
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
92 return AVERROR(EIO);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
93 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
94 if (packet_size > LMLM4_MAX_PACKET_SIZE) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
95 av_log(s, AV_LOG_ERROR, "packet size exceeds maximum\n");
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
96 return AVERROR(EIO);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
97 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
98
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
99 if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0)
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
100 return AVERROR(EIO);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
101
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
102 url_fskip(pb, padding);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
103
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
104 switch (frame_type) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
105 case LMLM4_I_FRAME:
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
106 pkt->flags = PKT_FLAG_KEY;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
107 case LMLM4_P_FRAME:
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
108 case LMLM4_B_FRAME:
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
109 pkt->stream_index = 0;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
110 break;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
111 case LMLM4_MPEG1L2:
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
112 pkt->stream_index = 1;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
113 break;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
114 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
115
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
116 return ret;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
117 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
118
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
119 AVInputFormat lmlm4_demuxer = {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
120 "lmlm4",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 2911
diff changeset
121 NULL_IF_CONFIG_SMALL("lmlm4 raw format"),
2911
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
122 0,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
123 lmlm4_probe,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
124 lmlm4_read_header,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
125 lmlm4_read_packet,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
126 };