00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "avformat.h"
00022 #include "internal.h"
00023
00024
00025 static int probe(AVProbeData *p)
00026 {
00027
00028 if( p->buf[0] == 1
00029 && p->buf[1] == 1
00030 && p->buf[2] == 3
00031 && p->buf[3] == 0xB8
00032 && p->buf[4] == 0x80
00033 && p->buf[5] == 0x60
00034 )
00035 return AVPROBE_SCORE_MAX-2;
00036
00037 return 0;
00038 }
00039
00040 static int read_header(AVFormatContext *s)
00041 {
00042 AVStream *st;
00043
00044 st = avformat_new_stream(s, NULL);
00045 if (!st)
00046 return AVERROR(ENOMEM);
00047
00048 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00049 st->codec->codec_id = AV_CODEC_ID_MPEG4;
00050 st->need_parsing = AVSTREAM_PARSE_FULL;
00051 avpriv_set_pts_info(st, 64, 1, 90000);
00052
00053 return 0;
00054
00055 }
00056
00057 static int read_packet(AVFormatContext *s, AVPacket *pkt)
00058 {
00059 int ret, size, pts, type, flags;
00060 int first_pkt = 0;
00061 int frame_complete = 0;
00062
00063 while (!frame_complete) {
00064
00065 type = avio_rb16(s->pb);
00066 size = avio_rb16(s->pb);
00067 flags = avio_rb16(s->pb);
00068 avio_rb16(s->pb);
00069 pts = avio_rb32(s->pb);
00070 avio_rb32(s->pb);
00071
00072 frame_complete = flags & 0x80;
00073
00074 size -= 12;
00075 if (size < 1)
00076 return -1;
00077
00078 if (type == 258) {
00079 avio_skip(s->pb, size);
00080 frame_complete = 0;
00081 continue;
00082 }
00083
00084 if (!first_pkt) {
00085 ret = av_get_packet(s->pb, pkt, size);
00086 if (ret < 0)
00087 return ret;
00088 first_pkt = 1;
00089 pkt->pts = pts;
00090 pkt->pos -= 16;
00091 } else {
00092 ret = av_append_packet(s->pb, pkt, size);
00093 if (ret < 0) {
00094 av_log(s, AV_LOG_ERROR, "failed to grow packet\n");
00095 av_free_packet(pkt);
00096 return ret;
00097 }
00098 }
00099 if (ret < size) {
00100 av_log(s, AV_LOG_ERROR, "Truncated packet! Read %d of %d bytes\n",
00101 ret, size);
00102 pkt->flags |= AV_PKT_FLAG_CORRUPT;
00103 break;
00104 }
00105 }
00106 pkt->stream_index = 0;
00107
00108 return 0;
00109 }
00110
00111 AVInputFormat ff_iv8_demuxer = {
00112 .name = "iv8",
00113 .long_name = NULL_IF_CONFIG_SMALL("IndigoVision 8000 video"),
00114 .read_probe = probe,
00115 .read_header = read_header,
00116 .read_packet = read_packet,
00117 .flags = AVFMT_GENERIC_INDEX,
00118 };