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