00001
00025 #include <stdlib.h>
00026 #include "avformat.h"
00027 #include "bitstream.h"
00028 #include "bytestream.h"
00029 #include "intreadwrite.h"
00030 #include "oggdec.h"
00031 #include "riff.h"
00032
00033 static int
00034 ogm_header(AVFormatContext *s, int idx)
00035 {
00036 ogg_t *ogg = s->priv_data;
00037 ogg_stream_t *os = ogg->streams + idx;
00038 AVStream *st = s->streams[idx];
00039 const uint8_t *p = os->buf + os->pstart;
00040 uint64_t time_unit;
00041 uint64_t spu;
00042 uint32_t default_len;
00043
00044 if(!(*p & 1))
00045 return 0;
00046 if(*p != 1)
00047 return 1;
00048
00049 p++;
00050
00051 if(*p == 'v'){
00052 int tag;
00053 st->codec->codec_type = CODEC_TYPE_VIDEO;
00054 p += 8;
00055 tag = bytestream_get_le32(&p);
00056 st->codec->codec_id = codec_get_id(codec_bmp_tags, tag);
00057 st->codec->codec_tag = tag;
00058 } else if (*p == 't') {
00059 st->codec->codec_type = CODEC_TYPE_SUBTITLE;
00060 st->codec->codec_id = CODEC_ID_TEXT;
00061 p += 12;
00062 } else {
00063 uint8_t acid[5];
00064 int cid;
00065 st->codec->codec_type = CODEC_TYPE_AUDIO;
00066 p += 8;
00067 bytestream_get_buffer(&p, acid, 4);
00068 acid[4] = 0;
00069 cid = strtol(acid, NULL, 16);
00070 st->codec->codec_id = codec_get_id(codec_wav_tags, cid);
00071 }
00072
00073 p += 4;
00074
00075 time_unit = bytestream_get_le64(&p);
00076 spu = bytestream_get_le64(&p);
00077 default_len = bytestream_get_le32(&p);
00078
00079 p += 8;
00080
00081 if(st->codec->codec_type == CODEC_TYPE_VIDEO){
00082 st->codec->width = bytestream_get_le32(&p);
00083 st->codec->height = bytestream_get_le32(&p);
00084 st->codec->time_base.den = spu * 10000000;
00085 st->codec->time_base.num = time_unit;
00086 st->time_base = st->codec->time_base;
00087 } else {
00088 st->codec->channels = bytestream_get_le16(&p);
00089 p += 2;
00090 st->codec->bit_rate = bytestream_get_le32(&p) * 8;
00091 st->codec->sample_rate = spu * 10000000 / time_unit;
00092 st->time_base.num = 1;
00093 st->time_base.den = st->codec->sample_rate;
00094 }
00095
00096 return 1;
00097 }
00098
00099 static int
00100 ogm_dshow_header(AVFormatContext *s, int idx)
00101 {
00102 ogg_t *ogg = s->priv_data;
00103 ogg_stream_t *os = ogg->streams + idx;
00104 AVStream *st = s->streams[idx];
00105 uint8_t *p = os->buf + os->pstart;
00106 uint32_t t;
00107
00108 if(!(*p & 1))
00109 return 0;
00110 if(*p != 1)
00111 return 1;
00112
00113 t = AV_RL32(p + 96);
00114
00115 if(t == 0x05589f80){
00116 st->codec->codec_type = CODEC_TYPE_VIDEO;
00117 st->codec->codec_id = codec_get_id(codec_bmp_tags, AV_RL32(p + 68));
00118 st->codec->time_base.den = 10000000;
00119 st->codec->time_base.num = AV_RL64(p + 164);
00120 st->codec->width = AV_RL32(p + 176);
00121 st->codec->height = AV_RL32(p + 180);
00122 } else if(t == 0x05589f81){
00123 st->codec->codec_type = CODEC_TYPE_AUDIO;
00124 st->codec->codec_id = codec_get_id(codec_wav_tags, AV_RL16(p + 124));
00125 st->codec->channels = AV_RL16(p + 126);
00126 st->codec->sample_rate = AV_RL32(p + 128);
00127 st->codec->bit_rate = AV_RL32(p + 132) * 8;
00128 }
00129
00130 return 1;
00131 }
00132
00133 static int
00134 ogm_packet(AVFormatContext *s, int idx)
00135 {
00136 ogg_t *ogg = s->priv_data;
00137 ogg_stream_t *os = ogg->streams + idx;
00138 uint8_t *p = os->buf + os->pstart;
00139 int lb;
00140
00141 if(*p & 8)
00142 os->pflags |= PKT_FLAG_KEY;
00143
00144 lb = ((*p & 2) << 1) | ((*p >> 6) & 3);
00145 os->pstart += lb + 1;
00146 os->psize -= lb + 1;
00147
00148 return 0;
00149 }
00150
00151 ogg_codec_t ogm_video_codec = {
00152 .magic = "\001video",
00153 .magicsize = 6,
00154 .header = ogm_header,
00155 .packet = ogm_packet
00156 };
00157
00158 ogg_codec_t ogm_audio_codec = {
00159 .magic = "\001audio",
00160 .magicsize = 6,
00161 .header = ogm_header,
00162 .packet = ogm_packet
00163 };
00164
00165 ogg_codec_t ogm_text_codec = {
00166 .magic = "\001text",
00167 .magicsize = 5,
00168 .header = ogm_header,
00169 .packet = ogm_packet
00170 };
00171
00172 ogg_codec_t ogm_old_codec = {
00173 .magic = "\001Direct Show Samples embedded in Ogg",
00174 .magicsize = 35,
00175 .header = ogm_dshow_header,
00176 .packet = ogm_packet
00177 };