annotate filmstripdec.c @ 5766:a292ef47e2f9 libavformat

Localize the #define _SVID_SOURCE needed for inet_aton() to os_support.c
author conrad
date Sun, 07 Mar 2010 19:48:59 +0000
parents ba6b1ac2bab6
children 536e5527c1e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5547
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
1 /*
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
2 * Adobe Filmstrip demuxer
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
3 * Copyright (c) 2010 Peter Ross
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
4 *
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
5 * This file is part of FFmpeg.
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
6 *
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
11 *
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
15 * Lesser General Public License for more details.
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
16 *
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
20 */
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
21
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
22 /**
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
23 * @file libavformat/filmstripdec.c
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
24 * Adobe Filmstrip demuxer
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
25 */
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
26
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
27 #include "libavutil/intreadwrite.h"
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
28 #include "avformat.h"
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
29
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
30 #define RAND_TAG MKBETAG('R','a','n','d')
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
31
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
32 typedef struct {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
33 int leading;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
34 } FilmstripDemuxContext;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
35
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
36 static int read_header(AVFormatContext *s,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
37 AVFormatParameters *ap)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
38 {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
39 FilmstripDemuxContext *film = s->priv_data;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
40 ByteIOContext *pb = s->pb;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
41 AVStream *st;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
42
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
43 if (url_is_streamed(s->pb))
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
44 return AVERROR(EIO);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
45
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
46 url_fseek(pb, url_fsize(pb) - 36, SEEK_SET);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
47 if (get_be32(pb) != RAND_TAG) {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
48 av_log(s, AV_LOG_ERROR, "magic number not found");
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
49 return AVERROR_INVALIDDATA;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
50 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
51
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
52 st = av_new_stream(s, 0);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
53 if (!st)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
54 return AVERROR(ENOMEM);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
55
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
56 st->nb_frames = get_be32(pb);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
57 if (get_be16(pb) != 0) {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
58 av_log_ask_for_sample(s, "unsupported packing method\n");
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
59 return AVERROR_INVALIDDATA;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
60 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
61
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
62 url_fskip(pb, 2);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
63 st->codec->codec_type = CODEC_TYPE_VIDEO;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
64 st->codec->codec_id = CODEC_ID_RAWVIDEO;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
65 st->codec->pix_fmt = PIX_FMT_RGBA;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
66 st->codec->codec_tag = 0; /* no fourcc */
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
67 st->codec->width = get_be16(pb);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
68 st->codec->height = get_be16(pb);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
69 film->leading = get_be16(pb);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
70 av_set_pts_info(st, 64, 1, get_be16(pb));
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
71
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
72 url_fseek(pb, 0, SEEK_SET);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
73
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
74 return 0;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
75 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
76
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
77 static int read_packet(AVFormatContext *s,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
78 AVPacket *pkt)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
79 {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
80 FilmstripDemuxContext *film = s->priv_data;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
81 AVStream *st = s->streams[0];
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
82
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
83 if (url_feof(s->pb))
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
84 return AVERROR(EIO);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
85 pkt->dts = url_ftell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
86 pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
87 url_fskip(s->pb, st->codec->width * film->leading * 4);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
88 if (pkt->size < 0)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
89 return pkt->size;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
90 pkt->flags |= PKT_FLAG_KEY;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
91 return 0;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
92 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
93
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
94 static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
95 {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
96 AVStream *st = s->streams[stream_index];
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
97 url_fseek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET);
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
98 return 0;
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
99 }
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
100
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
101 AVInputFormat filmstrip_demuxer = {
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
102 "filmstrip",
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
103 NULL_IF_CONFIG_SMALL("Adobe Filmstrip"),
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
104 sizeof(FilmstripDemuxContext),
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
105 NULL,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
106 read_header,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
107 read_packet,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
108 NULL,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
109 read_seek,
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
110 .extensions = "flm",
ba6b1ac2bab6 Adobe Filmstrip muxer and demuxer
pross
parents:
diff changeset
111 };