annotate lmlm4.c @ 5816:c587ece53810 libavformat

oggdec: Move PTS/DTS calculation to a function
author conrad
date Thu, 11 Mar 2010 07:17:53 +0000
parents 7d2f3f1b68d8
children 536e5527c1e0
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
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 3424
diff changeset
25 #include "libavutil/intreadwrite.h"
2911
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
26 #include "avformat.h"
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
27
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
28 #define LMLM4_I_FRAME 0x00
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
29 #define LMLM4_P_FRAME 0x01
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
30 #define LMLM4_B_FRAME 0x02
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
31 #define LMLM4_INVALID 0x03
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
32 #define LMLM4_MPEG1L2 0x04
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
33
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
34 #define LMLM4_MAX_PACKET_SIZE 1024 * 1024
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
35
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
36 static int lmlm4_probe(AVProbeData * pd) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
37 unsigned char *buf = pd->buf;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
38 unsigned int frame_type, packet_size;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
39
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
40 frame_type = AV_RB16(buf+2);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
41 packet_size = AV_RB32(buf+4);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
42
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
43 if (!AV_RB16(buf) && frame_type <= LMLM4_MPEG1L2 && packet_size &&
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
44 frame_type != LMLM4_INVALID && packet_size <= LMLM4_MAX_PACKET_SIZE) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
45
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
46 if (frame_type == LMLM4_MPEG1L2) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
47 if ((AV_RB16(buf+8) & 0xfffe) != 0xfffc)
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
48 return 0;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
49 /* I could calculate the audio framesize and compare with
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
50 * packet_size-8, but that seems overkill */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
51 return AVPROBE_SCORE_MAX / 3;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
52 } else if (AV_RB24(buf+8) == 0x000001) { /* PES Signal */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
53 return AVPROBE_SCORE_MAX / 5;
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
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
57 return 0;
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
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
60 static int lmlm4_read_header(AVFormatContext *s, AVFormatParameters *ap) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
61 AVStream *st;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
62
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
63 if (!(st = av_new_stream(s, 0)))
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
64 return AVERROR(ENOMEM);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
65 st->codec->codec_type = CODEC_TYPE_VIDEO;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
66 st->codec->codec_id = CODEC_ID_MPEG4;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
67 st->need_parsing = AVSTREAM_PARSE_HEADERS;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
68 av_set_pts_info(st, 64, 1001, 30000);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
69
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
70 if (!(st = av_new_stream(s, 1)))
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
71 return AVERROR(ENOMEM);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
72 st->codec->codec_type = CODEC_TYPE_AUDIO;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
73 st->codec->codec_id = CODEC_ID_MP2;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
74 st->need_parsing = AVSTREAM_PARSE_HEADERS;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
75
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
76 /* the parameters will be extracted from the compressed bitstream */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
77 return 0;
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
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
80 static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
81 ByteIOContext *pb = s->pb;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
82 int ret;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
83 unsigned int frame_type, packet_size, padding, frame_size;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
84
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
85 get_be16(pb); /* channel number */
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
86 frame_type = get_be16(pb);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
87 packet_size = get_be32(pb);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
88 padding = -packet_size & 511;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
89 frame_size = packet_size - 8;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
90
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
91 if (frame_type > LMLM4_MPEG1L2 || frame_type == LMLM4_INVALID) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
92 av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n");
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
93 return AVERROR(EIO);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
94 }
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
95 if (packet_size > LMLM4_MAX_PACKET_SIZE) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
96 av_log(s, AV_LOG_ERROR, "packet size exceeds maximum\n");
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
97 return AVERROR(EIO);
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
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
100 if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0)
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
101 return AVERROR(EIO);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
102
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
103 url_fskip(pb, padding);
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
104
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
105 switch (frame_type) {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
106 case LMLM4_I_FRAME:
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
107 pkt->flags = PKT_FLAG_KEY;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
108 case LMLM4_P_FRAME:
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
109 case LMLM4_B_FRAME:
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
110 pkt->stream_index = 0;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
111 break;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
112 case LMLM4_MPEG1L2:
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
113 pkt->stream_index = 1;
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
114 break;
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
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
117 return ret;
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
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
120 AVInputFormat lmlm4_demuxer = {
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
121 "lmlm4",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 2911
diff changeset
122 NULL_IF_CONFIG_SMALL("lmlm4 raw format"),
2911
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
123 0,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
124 lmlm4_probe,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
125 lmlm4_read_header,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
126 lmlm4_read_packet,
ae79fd89ca8b Linux Media Labs MPEG-4 (LMLM4) demuxer
ivo
parents:
diff changeset
127 };