00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "avformat.h"
00026
00027 #define LMLM4_I_FRAME 0x00
00028 #define LMLM4_P_FRAME 0x01
00029 #define LMLM4_B_FRAME 0x02
00030 #define LMLM4_INVALID 0x03
00031 #define LMLM4_MPEG1L2 0x04
00032
00033 #define LMLM4_MAX_PACKET_SIZE 1024 * 1024
00034
00035 static int lmlm4_probe(AVProbeData * pd) {
00036 unsigned char *buf = pd->buf;
00037 unsigned int frame_type, packet_size;
00038
00039 frame_type = AV_RB16(buf+2);
00040 packet_size = AV_RB32(buf+4);
00041
00042 if (!AV_RB16(buf) && frame_type <= LMLM4_MPEG1L2 && packet_size &&
00043 frame_type != LMLM4_INVALID && packet_size <= LMLM4_MAX_PACKET_SIZE) {
00044
00045 if (frame_type == LMLM4_MPEG1L2) {
00046 if ((AV_RB16(buf+8) & 0xfffe) != 0xfffc)
00047 return 0;
00048
00049
00050 return AVPROBE_SCORE_MAX / 3;
00051 } else if (AV_RB24(buf+8) == 0x000001) {
00052 return AVPROBE_SCORE_MAX / 5;
00053 }
00054 }
00055
00056 return 0;
00057 }
00058
00059 static int lmlm4_read_header(AVFormatContext *s, AVFormatParameters *ap) {
00060 AVStream *st;
00061
00062 if (!(st = av_new_stream(s, 0)))
00063 return AVERROR(ENOMEM);
00064 st->codec->codec_type = CODEC_TYPE_VIDEO;
00065 st->codec->codec_id = CODEC_ID_MPEG4;
00066 st->need_parsing = AVSTREAM_PARSE_HEADERS;
00067 av_set_pts_info(st, 64, 1001, 30000);
00068
00069 if (!(st = av_new_stream(s, 1)))
00070 return AVERROR(ENOMEM);
00071 st->codec->codec_type = CODEC_TYPE_AUDIO;
00072 st->codec->codec_id = CODEC_ID_MP2;
00073 st->need_parsing = AVSTREAM_PARSE_HEADERS;
00074
00075
00076 return 0;
00077 }
00078
00079 static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) {
00080 ByteIOContext *pb = s->pb;
00081 int ret;
00082 unsigned int frame_type, packet_size, padding, frame_size;
00083
00084 get_be16(pb);
00085 frame_type = get_be16(pb);
00086 packet_size = get_be32(pb);
00087 padding = -packet_size & 511;
00088 frame_size = packet_size - 8;
00089
00090 if (frame_type > LMLM4_MPEG1L2 || frame_type == LMLM4_INVALID) {
00091 av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n");
00092 return AVERROR(EIO);
00093 }
00094 if (packet_size > LMLM4_MAX_PACKET_SIZE) {
00095 av_log(s, AV_LOG_ERROR, "packet size exceeds maximum\n");
00096 return AVERROR(EIO);
00097 }
00098
00099 if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0)
00100 return AVERROR(EIO);
00101
00102 url_fskip(pb, padding);
00103
00104 switch (frame_type) {
00105 case LMLM4_I_FRAME:
00106 pkt->flags = PKT_FLAG_KEY;
00107 case LMLM4_P_FRAME:
00108 case LMLM4_B_FRAME:
00109 pkt->stream_index = 0;
00110 break;
00111 case LMLM4_MPEG1L2:
00112 pkt->stream_index = 1;
00113 break;
00114 }
00115
00116 return ret;
00117 }
00118
00119 AVInputFormat lmlm4_demuxer = {
00120 "lmlm4",
00121 "lmlm4 raw format",
00122 0,
00123 lmlm4_probe,
00124 lmlm4_read_header,
00125 lmlm4_read_packet,
00126 };