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