83ab7f18 |
/*
* Adobe Filmstrip demuxer
* Copyright (c) 2010 Peter Ross
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** |
ba87f080 |
* @file |
83ab7f18 |
* Adobe Filmstrip demuxer
*/
#include "libavutil/intreadwrite.h" |
25012c56 |
#include "libavutil/imgutils.h" |
83ab7f18 |
#include "avformat.h" |
c3f9ebf7 |
#include "internal.h" |
83ab7f18 |
#define RAND_TAG MKBETAG('R','a','n','d')
|
daf8cf35 |
typedef struct FilmstripDemuxContext { |
83ab7f18 |
int leading;
} FilmstripDemuxContext;
|
6e9651d1 |
static int read_header(AVFormatContext *s) |
83ab7f18 |
{
FilmstripDemuxContext *film = s->priv_data; |
471fe57e |
AVIOContext *pb = s->pb; |
83ab7f18 |
AVStream *st;
|
83548fe8 |
if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) |
83ab7f18 |
return AVERROR(EIO);
|
db44ea96 |
avio_seek(pb, avio_size(pb) - 36, SEEK_SET); |
e63a3628 |
if (avio_rb32(pb) != RAND_TAG) { |
d2b927d4 |
av_log(s, AV_LOG_ERROR, "magic number not found\n"); |
83ab7f18 |
return AVERROR_INVALIDDATA;
}
|
3b3bbdd3 |
st = avformat_new_stream(s, NULL); |
83ab7f18 |
if (!st)
return AVERROR(ENOMEM);
|
e63a3628 |
st->nb_frames = avio_rb32(pb);
if (avio_rb16(pb) != 0) { |
1ecdf891 |
avpriv_request_sample(s, "Unsupported packing method"); |
f3298f12 |
return AVERROR_PATCHWELCOME; |
83ab7f18 |
}
|
45a8a02a |
avio_skip(pb, 2); |
9200514a |
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codecpar->format = AV_PIX_FMT_RGBA;
st->codecpar->codec_tag = 0; /* no fourcc */
st->codecpar->width = avio_rb16(pb);
st->codecpar->height = avio_rb16(pb); |
e63a3628 |
film->leading = avio_rb16(pb); |
9612dcd6 |
|
25012c56 |
if (av_image_check_size(st->codecpar->width, st->codecpar->height, 0, s) < 0)
return AVERROR_INVALIDDATA; |
9612dcd6 |
|
c3f9ebf7 |
avpriv_set_pts_info(st, 64, 1, avio_rb16(pb)); |
83ab7f18 |
|
f59d8ff8 |
avio_seek(pb, 0, SEEK_SET); |
83ab7f18 |
return 0;
}
static int read_packet(AVFormatContext *s,
AVPacket *pkt)
{
FilmstripDemuxContext *film = s->priv_data;
AVStream *st = s->streams[0];
|
d34ec64a |
if (avio_feof(s->pb)) |
83ab7f18 |
return AVERROR(EIO); |
6f69f7a8 |
pkt->dts = avio_tell(s->pb) / (st->codecpar->width * (int64_t)(st->codecpar->height + film->leading) * 4); |
9200514a |
pkt->size = av_get_packet(s->pb, pkt, st->codecpar->width * st->codecpar->height * 4);
avio_skip(s->pb, st->codecpar->width * (int64_t) film->leading * 4); |
83ab7f18 |
if (pkt->size < 0)
return pkt->size; |
cc947f04 |
pkt->flags |= AV_PKT_FLAG_KEY; |
83ab7f18 |
return 0;
}
static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
{
AVStream *st = s->streams[stream_index]; |
9200514a |
if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codecpar->width * st->codecpar->height * 4, SEEK_SET) < 0) |
58540d7b |
return -1; |
83ab7f18 |
return 0;
}
|
66355be3 |
AVInputFormat ff_filmstrip_demuxer = { |
dfc2c4d9 |
.name = "filmstrip",
.long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
.priv_data_size = sizeof(FilmstripDemuxContext),
.read_header = read_header,
.read_packet = read_packet,
.read_seek = read_seek, |
20234a4b |
.extensions = "flm", |
83ab7f18 |
}; |