00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "libavutil/intreadwrite.h"
00028 #include "avformat.h"
00029 #include "internal.h"
00030
00031 #define RAND_TAG MKBETAG('R','a','n','d')
00032
00033 typedef struct {
00034 int leading;
00035 } FilmstripDemuxContext;
00036
00037 static int read_header(AVFormatContext *s,
00038 AVFormatParameters *ap)
00039 {
00040 FilmstripDemuxContext *film = s->priv_data;
00041 AVIOContext *pb = s->pb;
00042 AVStream *st;
00043
00044 if (!s->pb->seekable)
00045 return AVERROR(EIO);
00046
00047 avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
00048 if (avio_rb32(pb) != RAND_TAG) {
00049 av_log(s, AV_LOG_ERROR, "magic number not found");
00050 return AVERROR_INVALIDDATA;
00051 }
00052
00053 st = avformat_new_stream(s, NULL);
00054 if (!st)
00055 return AVERROR(ENOMEM);
00056
00057 st->nb_frames = avio_rb32(pb);
00058 if (avio_rb16(pb) != 0) {
00059 av_log_ask_for_sample(s, "unsupported packing method\n");
00060 return AVERROR_INVALIDDATA;
00061 }
00062
00063 avio_skip(pb, 2);
00064 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00065 st->codec->codec_id = CODEC_ID_RAWVIDEO;
00066 st->codec->pix_fmt = PIX_FMT_RGBA;
00067 st->codec->codec_tag = 0;
00068 st->codec->width = avio_rb16(pb);
00069 st->codec->height = avio_rb16(pb);
00070 film->leading = avio_rb16(pb);
00071 avpriv_set_pts_info(st, 64, 1, avio_rb16(pb));
00072
00073 avio_seek(pb, 0, SEEK_SET);
00074
00075 return 0;
00076 }
00077
00078 static int read_packet(AVFormatContext *s,
00079 AVPacket *pkt)
00080 {
00081 FilmstripDemuxContext *film = s->priv_data;
00082 AVStream *st = s->streams[0];
00083
00084 if (url_feof(s->pb))
00085 return AVERROR(EIO);
00086 pkt->dts = avio_tell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4);
00087 pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4);
00088 avio_skip(s->pb, st->codec->width * film->leading * 4);
00089 if (pkt->size < 0)
00090 return pkt->size;
00091 pkt->flags |= AV_PKT_FLAG_KEY;
00092 return 0;
00093 }
00094
00095 static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
00096 {
00097 AVStream *st = s->streams[stream_index];
00098 if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET) < 0)
00099 return -1;
00100 return 0;
00101 }
00102
00103 AVInputFormat ff_filmstrip_demuxer = {
00104 .name = "filmstrip",
00105 .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
00106 .priv_data_size = sizeof(FilmstripDemuxContext),
00107 .read_header = read_header,
00108 .read_packet = read_packet,
00109 .read_seek = read_seek,
00110 .extensions = "flm",
00111 };