annotate oggparsedirac.c @ 5605:32fe8ab7e6b6 libavformat

10l trocadero: now return value of ff_rtmp_packet_read() has different meaning
author kostya
date Sat, 30 Jan 2010 09:45:52 +0000
parents 52c7b29eca31
children 14f90d20ef05
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
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
42 st->codec->codec_type = CODEC_TYPE_VIDEO;
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!)
5514
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
50 static uint64_t dirac_gptopts(AVFormatContext *s, int idx, int64_t gp,
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 {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
53 struct ogg *ogg = s->priv_data;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
54 struct ogg_stream *os = ogg->streams + idx;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
55
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
56 unsigned dist = ((gp >> 14) & 0xff00) | (gp & 0xff);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
57 int64_t dts = (gp >> 31);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
58 int64_t pts = dts + ((gp >> 9) & 0x1fff);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
59
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
60 if (!dist)
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
61 os->pflags |= PKT_FLAG_KEY;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
62
5514
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
63 if (dts_out)
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
64 *dts_out = dts;
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
65
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
66 return pts;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
67 }
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
68
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
69 static int old_dirac_header(AVFormatContext *s, int idx)
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
70 {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
71 struct ogg *ogg = s->priv_data;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
72 struct ogg_stream *os = ogg->streams + idx;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
73 AVStream *st = s->streams[idx];
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
74 uint8_t *buf = os->buf + os->pstart;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
75
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
76 if (buf[0] != 'K')
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
77 return 0;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
78
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
79 st->codec->codec_type = CODEC_TYPE_VIDEO;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
80 st->codec->codec_id = CODEC_ID_DIRAC;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
81 st->time_base.den = AV_RB32(buf+8);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
82 st->time_base.num = AV_RB32(buf+12);
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
83 return 1;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
84 }
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
85
5514
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
86 static uint64_t old_dirac_gptopts(AVFormatContext *s, int idx, uint64_t gp,
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
87 int64_t *dts)
5512
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
88 {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
89 struct ogg *ogg = s->priv_data;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
90 struct ogg_stream *os = ogg->streams + idx;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
91 uint64_t iframe = gp >> 30;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
92 uint64_t pframe = gp & 0x3fffffff;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
93
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
94 if (!pframe)
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
95 os->pflags |= PKT_FLAG_KEY;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
96
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
97 return iframe + pframe;
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
98 }
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
99
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
100 const struct ogg_codec ff_dirac_codec = {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
101 .magic = "BBCD\0",
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
102 .magicsize = 5,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
103 .header = dirac_header,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
104 .gptopts = dirac_gptopts,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
105 .granule_is_start = 1,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
106 };
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
107
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
108 const struct ogg_codec ff_old_dirac_codec = {
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
109 .magic = "KW-DIRAC",
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
110 .magicsize = 8,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
111 .header = old_dirac_header,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
112 .gptopts = old_dirac_gptopts,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
113 .granule_is_start = 1,
60671fac35ad Add support for dirac in ogg
conrad
parents:
diff changeset
114 };