yading@11
|
1 /*
|
yading@11
|
2 * Copyright (C) 2008 David Conrad
|
yading@11
|
3 *
|
yading@11
|
4 * This file is part of FFmpeg.
|
yading@11
|
5 *
|
yading@11
|
6 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
7 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
8 * License as published by the Free Software Foundation; either
|
yading@11
|
9 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
10 *
|
yading@11
|
11 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
14 * Lesser General Public License for more details.
|
yading@11
|
15 *
|
yading@11
|
16 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
17 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
19 */
|
yading@11
|
20
|
yading@11
|
21 #include "libavcodec/get_bits.h"
|
yading@11
|
22 #include "libavcodec/dirac.h"
|
yading@11
|
23 #include "avformat.h"
|
yading@11
|
24 #include "internal.h"
|
yading@11
|
25 #include "oggdec.h"
|
yading@11
|
26
|
yading@11
|
27 static int dirac_header(AVFormatContext *s, int idx)
|
yading@11
|
28 {
|
yading@11
|
29 struct ogg *ogg = s->priv_data;
|
yading@11
|
30 struct ogg_stream *os = ogg->streams + idx;
|
yading@11
|
31 AVStream *st = s->streams[idx];
|
yading@11
|
32 dirac_source_params source;
|
yading@11
|
33 GetBitContext gb;
|
yading@11
|
34
|
yading@11
|
35 // already parsed the header
|
yading@11
|
36 if (st->codec->codec_id == AV_CODEC_ID_DIRAC)
|
yading@11
|
37 return 0;
|
yading@11
|
38
|
yading@11
|
39 init_get_bits(&gb, os->buf + os->pstart + 13, (os->psize - 13) * 8);
|
yading@11
|
40 if (avpriv_dirac_parse_sequence_header(st->codec, &gb, &source) < 0)
|
yading@11
|
41 return -1;
|
yading@11
|
42
|
yading@11
|
43 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
yading@11
|
44 st->codec->codec_id = AV_CODEC_ID_DIRAC;
|
yading@11
|
45 // dirac in ogg always stores timestamps as though the video were interlaced
|
yading@11
|
46 avpriv_set_pts_info(st, 64, st->codec->time_base.num, 2*st->codec->time_base.den);
|
yading@11
|
47 return 1;
|
yading@11
|
48 }
|
yading@11
|
49
|
yading@11
|
50 // various undocument things: granule is signed (only for dirac!)
|
yading@11
|
51 static uint64_t dirac_gptopts(AVFormatContext *s, int idx, uint64_t granule,
|
yading@11
|
52 int64_t *dts_out)
|
yading@11
|
53 {
|
yading@11
|
54 int64_t gp = granule;
|
yading@11
|
55 struct ogg *ogg = s->priv_data;
|
yading@11
|
56 struct ogg_stream *os = ogg->streams + idx;
|
yading@11
|
57
|
yading@11
|
58 unsigned dist = ((gp >> 14) & 0xff00) | (gp & 0xff);
|
yading@11
|
59 int64_t dts = (gp >> 31);
|
yading@11
|
60 int64_t pts = dts + ((gp >> 9) & 0x1fff);
|
yading@11
|
61
|
yading@11
|
62 if (!dist)
|
yading@11
|
63 os->pflags |= AV_PKT_FLAG_KEY;
|
yading@11
|
64
|
yading@11
|
65 if (dts_out)
|
yading@11
|
66 *dts_out = dts;
|
yading@11
|
67
|
yading@11
|
68 return pts;
|
yading@11
|
69 }
|
yading@11
|
70
|
yading@11
|
71 static int old_dirac_header(AVFormatContext *s, int idx)
|
yading@11
|
72 {
|
yading@11
|
73 struct ogg *ogg = s->priv_data;
|
yading@11
|
74 struct ogg_stream *os = ogg->streams + idx;
|
yading@11
|
75 AVStream *st = s->streams[idx];
|
yading@11
|
76 uint8_t *buf = os->buf + os->pstart;
|
yading@11
|
77
|
yading@11
|
78 if (buf[0] != 'K')
|
yading@11
|
79 return 0;
|
yading@11
|
80
|
yading@11
|
81 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
yading@11
|
82 st->codec->codec_id = AV_CODEC_ID_DIRAC;
|
yading@11
|
83 avpriv_set_pts_info(st, 64, AV_RB32(buf+12), AV_RB32(buf+8));
|
yading@11
|
84 return 1;
|
yading@11
|
85 }
|
yading@11
|
86
|
yading@11
|
87 static uint64_t old_dirac_gptopts(AVFormatContext *s, int idx, uint64_t gp,
|
yading@11
|
88 int64_t *dts)
|
yading@11
|
89 {
|
yading@11
|
90 struct ogg *ogg = s->priv_data;
|
yading@11
|
91 struct ogg_stream *os = ogg->streams + idx;
|
yading@11
|
92 uint64_t iframe = gp >> 30;
|
yading@11
|
93 uint64_t pframe = gp & 0x3fffffff;
|
yading@11
|
94
|
yading@11
|
95 if (!pframe)
|
yading@11
|
96 os->pflags |= AV_PKT_FLAG_KEY;
|
yading@11
|
97
|
yading@11
|
98 return iframe + pframe;
|
yading@11
|
99 }
|
yading@11
|
100
|
yading@11
|
101 const struct ogg_codec ff_dirac_codec = {
|
yading@11
|
102 .magic = "BBCD\0",
|
yading@11
|
103 .magicsize = 5,
|
yading@11
|
104 .header = dirac_header,
|
yading@11
|
105 .gptopts = dirac_gptopts,
|
yading@11
|
106 .granule_is_start = 1,
|
yading@11
|
107 .nb_header = 1,
|
yading@11
|
108 };
|
yading@11
|
109
|
yading@11
|
110 const struct ogg_codec ff_old_dirac_codec = {
|
yading@11
|
111 .magic = "KW-DIRAC",
|
yading@11
|
112 .magicsize = 8,
|
yading@11
|
113 .header = old_dirac_header,
|
yading@11
|
114 .gptopts = old_dirac_gptopts,
|
yading@11
|
115 .granule_is_start = 1,
|
yading@11
|
116 .nb_header = 1,
|
yading@11
|
117 };
|