annotate oggparsedirac.c @ 6460:e29a553aa1fc libavformat

Move INET6_ADDRSTRLEN to network.h, similar to other network-related fixups for broken OSes. This is included in rtsp.h, as opposed to os_support.h. Should fix OS/2 broken build on fate.
author rbultje
date Fri, 03 Sep 2010 20:06:01 +0000
parents 11bb10c37225
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
1 /*
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
2 * Copyright (C) 2008 David Conrad
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
3 *
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
4 * This file is part of FFmpeg.
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
5 *
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
10 *
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
14 * Lesser General Public License for more details.
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
15 *
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
19 */
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
20
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
21 #include "libavcodec/get_bits.h"
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
22 #include "libavcodec/dirac.h"
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
23 #include "avformat.h"
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
24 #include "oggdec.h"
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
25
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
26 static int dirac_header(AVFormatContext *s, int idx)
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
27 {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
28 struct ogg *ogg = s->priv_data;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
29 struct ogg_stream *os = ogg->streams + idx;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
30 AVStream *st = s->streams[idx];
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
31 dirac_source_params source;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
32 GetBitContext gb;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
33
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
34 // already parsed the header
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
35 if (st->codec->codec_id == CODEC_ID_DIRAC)
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
36 return 0;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
37
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
38 init_get_bits(&gb, os->buf + os->pstart + 13, (os->psize - 13) * 8);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
39 if (ff_dirac_parse_sequence_header(st->codec, &gb, &source) < 0)
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
40 return -1;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
41
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5763
diff changeset
42 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
43 st->codec->codec_id = CODEC_ID_DIRAC;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
44 // dirac in ogg always stores timestamps as though the video were interlaced
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
45 st->time_base = (AVRational){st->codec->time_base.num, 2*st->codec->time_base.den};
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
46 return 1;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
47 }
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
48
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
49 // various undocument things: granule is signed (only for dirac!)
5763
14f90d20ef05 Fix warning about incompatible pointer types
conrad
parents: 5514
diff changeset
50 static uint64_t dirac_gptopts(AVFormatContext *s, int idx, uint64_t granule,
5514
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
51 int64_t *dts_out)
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
52 {
5763
14f90d20ef05 Fix warning about incompatible pointer types
conrad
parents: 5514
diff changeset
53 int64_t gp = granule;
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
54 struct ogg *ogg = s->priv_data;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
55 struct ogg_stream *os = ogg->streams + idx;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
56
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
57 unsigned dist = ((gp >> 14) & 0xff00) | (gp & 0xff);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
58 int64_t dts = (gp >> 31);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
59 int64_t pts = dts + ((gp >> 9) & 0x1fff);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
60
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
61 if (!dist)
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
62 os->pflags |= AV_PKT_FLAG_KEY;
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
63
5514
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
64 if (dts_out)
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
65 *dts_out = dts;
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
66
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
67 return pts;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
68 }
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
69
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
70 static int old_dirac_header(AVFormatContext *s, int idx)
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
71 {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
72 struct ogg *ogg = s->priv_data;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
73 struct ogg_stream *os = ogg->streams + idx;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
74 AVStream *st = s->streams[idx];
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
75 uint8_t *buf = os->buf + os->pstart;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
76
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
77 if (buf[0] != 'K')
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
78 return 0;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
79
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5763
diff changeset
80 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
81 st->codec->codec_id = CODEC_ID_DIRAC;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
82 st->time_base.den = AV_RB32(buf+8);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
83 st->time_base.num = AV_RB32(buf+12);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
84 return 1;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
85 }
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
86
5514
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
87 static uint64_t old_dirac_gptopts(AVFormatContext *s, int idx, uint64_t gp,
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
88 int64_t *dts)
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
89 {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
90 struct ogg *ogg = s->priv_data;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
91 struct ogg_stream *os = ogg->streams + idx;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
92 uint64_t iframe = gp >> 30;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
93 uint64_t pframe = gp & 0x3fffffff;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
94
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
95 if (!pframe)
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
96 os->pflags |= AV_PKT_FLAG_KEY;
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
97
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
98 return iframe + pframe;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
99 }
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
100
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
101 const struct ogg_codec ff_dirac_codec = {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
102 .magic = "BBCD\0",
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
103 .magicsize = 5,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
104 .header = dirac_header,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
105 .gptopts = dirac_gptopts,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
106 .granule_is_start = 1,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
107 };
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
108
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
109 const struct ogg_codec ff_old_dirac_codec = {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
110 .magic = "KW-DIRAC",
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
111 .magicsize = 8,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
112 .header = old_dirac_header,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
113 .gptopts = old_dirac_gptopts,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
114 .granule_is_start = 1,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
115 };