Libav 0.7.1
|
00001 /* 00002 * Copyright (C) 2008 David Conrad 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include "libavcodec/get_bits.h" 00022 #include "libavcodec/dirac.h" 00023 #include "avformat.h" 00024 #include "oggdec.h" 00025 00026 static int dirac_header(AVFormatContext *s, int idx) 00027 { 00028 struct ogg *ogg = s->priv_data; 00029 struct ogg_stream *os = ogg->streams + idx; 00030 AVStream *st = s->streams[idx]; 00031 dirac_source_params source; 00032 GetBitContext gb; 00033 00034 // already parsed the header 00035 if (st->codec->codec_id == CODEC_ID_DIRAC) 00036 return 0; 00037 00038 init_get_bits(&gb, os->buf + os->pstart + 13, (os->psize - 13) * 8); 00039 if (ff_dirac_parse_sequence_header(st->codec, &gb, &source) < 0) 00040 return -1; 00041 00042 st->codec->codec_type = AVMEDIA_TYPE_VIDEO; 00043 st->codec->codec_id = CODEC_ID_DIRAC; 00044 // dirac in ogg always stores timestamps as though the video were interlaced 00045 av_set_pts_info(st, 64, st->codec->time_base.num, 2*st->codec->time_base.den); 00046 return 1; 00047 } 00048 00049 // various undocument things: granule is signed (only for dirac!) 00050 static uint64_t dirac_gptopts(AVFormatContext *s, int idx, uint64_t granule, 00051 int64_t *dts_out) 00052 { 00053 int64_t gp = granule; 00054 struct ogg *ogg = s->priv_data; 00055 struct ogg_stream *os = ogg->streams + idx; 00056 00057 unsigned dist = ((gp >> 14) & 0xff00) | (gp & 0xff); 00058 int64_t dts = (gp >> 31); 00059 int64_t pts = dts + ((gp >> 9) & 0x1fff); 00060 00061 if (!dist) 00062 os->pflags |= AV_PKT_FLAG_KEY; 00063 00064 if (dts_out) 00065 *dts_out = dts; 00066 00067 return pts; 00068 } 00069 00070 static int old_dirac_header(AVFormatContext *s, int idx) 00071 { 00072 struct ogg *ogg = s->priv_data; 00073 struct ogg_stream *os = ogg->streams + idx; 00074 AVStream *st = s->streams[idx]; 00075 uint8_t *buf = os->buf + os->pstart; 00076 00077 if (buf[0] != 'K') 00078 return 0; 00079 00080 st->codec->codec_type = AVMEDIA_TYPE_VIDEO; 00081 st->codec->codec_id = CODEC_ID_DIRAC; 00082 av_set_pts_info(st, 64, AV_RB32(buf+12), AV_RB32(buf+8)); 00083 return 1; 00084 } 00085 00086 static uint64_t old_dirac_gptopts(AVFormatContext *s, int idx, uint64_t gp, 00087 int64_t *dts) 00088 { 00089 struct ogg *ogg = s->priv_data; 00090 struct ogg_stream *os = ogg->streams + idx; 00091 uint64_t iframe = gp >> 30; 00092 uint64_t pframe = gp & 0x3fffffff; 00093 00094 if (!pframe) 00095 os->pflags |= AV_PKT_FLAG_KEY; 00096 00097 return iframe + pframe; 00098 } 00099 00100 const struct ogg_codec ff_dirac_codec = { 00101 .magic = "BBCD\0", 00102 .magicsize = 5, 00103 .header = dirac_header, 00104 .gptopts = dirac_gptopts, 00105 .granule_is_start = 1, 00106 }; 00107 00108 const struct ogg_codec ff_old_dirac_codec = { 00109 .magic = "KW-DIRAC", 00110 .magicsize = 8, 00111 .header = old_dirac_header, 00112 .gptopts = old_dirac_gptopts, 00113 .granule_is_start = 1, 00114 };