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