} else {
/* video codec info */
put_be32(s,34); /* size */
- put_tag(s,"VIDORV10");
+ if(stream->enc->codec_id == CODEC_ID_RV10)
+ put_tag(s,"VIDORV10");
+ else
+ put_tag(s,"VIDORV20");
put_be16(s, stream->enc->width);
put_be16(s, stream->enc->height);
put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */
/* Seems to be the codec version: only use basic H263. The next
versions seems to add a diffential DC coding as in
MPEG... nothing new under the sun */
- put_be32(s,0x10000000);
+ if(stream->enc->codec_id == CODEC_ID_RV10)
+ put_be32(s,0x10000000);
+ else
+ put_be32(s,0x20103001);
//put_be32(s,0x10003000);
}
}
break;
case CODEC_TYPE_VIDEO:
rm->video_stream = stream;
- stream->frame_rate = (float)codec->frame_rate / (float)codec->frame_rate_base;
+ stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num;
/* XXX: dummy values */
stream->packet_max_size = 4096;
stream->nb_packets = 0;
} else {
put_byte(pb, 0x01);
}
- put_be16(pb, 0x4000 | (size)); /* total frame size */
- put_be16(pb, 0x4000 | (size)); /* offset from the start or the end */
+ put_be16(pb, 0x4000 + (size)); /* total frame size */
+ put_be16(pb, 0x4000 + (size)); /* offset from the start or the end */
#else
/* full frame */
write_packet_header(s, size + 6);
put_byte(pb, 0xc0);
- put_be16(pb, 0x4000 | size); /* total frame size */
+ put_be16(pb, 0x4000 + size); /* total frame size */
put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
#endif
put_byte(pb, stream->nb_frames & 0xff);
st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = CODEC_ID_RA_144;
} else {
+ int flavor, sub_packet_h, coded_framesize;
/* old version (4) */
get_be32(pb); /* .ra4 */
- get_be32(pb);
- get_be16(pb);
+ get_be32(pb); /* data size */
+ get_be16(pb); /* version2 */
get_be32(pb); /* header size */
- get_be16(pb); /* add codec info */
- get_be32(pb); /* coded frame size */
+ flavor= get_be16(pb); /* add codec info / flavor */
+ coded_framesize= get_be32(pb); /* coded frame size */
get_be32(pb); /* ??? */
get_be32(pb); /* ??? */
get_be32(pb); /* ??? */
- get_be16(pb); /* 1 */
- get_be16(pb); /* coded frame size */
- get_be32(pb);
+ sub_packet_h= get_be16(pb); /* 1 */
+ st->codec.block_align= get_be16(pb); /* frame size */
+ get_be16(pb); /* sub packet size */
+ get_be16(pb); /* ??? */
st->codec.sample_rate = get_be16(pb);
get_be32(pb);
st->codec.channels = get_be16(pb);
st->codec.codec_type = CODEC_TYPE_AUDIO;
if (!strcmp(buf, "dnet")) {
st->codec.codec_id = CODEC_ID_AC3;
+ } else if (!strcmp(buf, "28_8")) {
+ st->codec.codec_id = CODEC_ID_RA_288;
+ st->codec.extradata_size= 10;
+ st->codec.extradata= av_mallocz(st->codec.extradata_size);
+ /* this is completly braindead and broken, the idiot who added this codec and endianness
+ specific reordering to mplayer and libavcodec/ra288.c should be drowned in a see of cola */
+ //FIXME pass the unpermutated extradata
+ ((uint16_t*)st->codec.extradata)[1]= sub_packet_h;
+ ((uint16_t*)st->codec.extradata)[2]= flavor;
+ ((uint16_t*)st->codec.extradata)[3]= coded_framesize;
} else {
st->codec.codec_id = CODEC_ID_NONE;
pstrcpy(st->codec.codec_name, sizeof(st->codec.codec_name),
tag,
tag_size);
#endif
- if (tag_size < 10)
+ if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
goto fail;
switch(tag) {
case MKTAG('P', 'R', 'O', 'P'):
start_time = get_be32(pb); /* start time */
get_be32(pb); /* preroll */
duration = get_be32(pb); /* duration */
- st->start_time = start_time * (AV_TIME_BASE / 1000);
- st->duration = duration * (AV_TIME_BASE / 1000);
+ st->start_time = start_time;
+ st->duration = duration;
get_str8(pb, buf, sizeof(buf)); /* desc */
get_str8(pb, buf, sizeof(buf)); /* mimetype */
codec_data_size = get_be32(pb);
st->codec.codec_tag = get_le32(pb);
// av_log(NULL, AV_LOG_DEBUG, "%X %X\n", st->codec.codec_tag, MKTAG('R', 'V', '2', '0'));
if ( st->codec.codec_tag != MKTAG('R', 'V', '1', '0')
- && st->codec.codec_tag != MKTAG('R', 'V', '2', '0'))
+ && st->codec.codec_tag != MKTAG('R', 'V', '2', '0')
+ && st->codec.codec_tag != MKTAG('R', 'V', '3', '0')
+ && st->codec.codec_tag != MKTAG('R', 'V', '4', '0'))
goto fail1;
st->codec.width = get_be16(pb);
st->codec.height = get_be16(pb);
- st->codec.frame_rate_base= 1;
+ st->codec.time_base.num= 1;
fps= get_be16(pb);
st->codec.codec_type = CODEC_TYPE_VIDEO;
get_be32(pb);
get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
// av_log(NULL, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2);
- st->codec.frame_rate = fps * st->codec.frame_rate_base;
+ st->codec.time_base.den = fps * st->codec.time_base.num;
/* modification of h263 codec version (!) */
#ifdef WORDS_BIGENDIAN
h263_hack_version = ((uint32_t*)st->codec.extradata)[1];
h263_hack_version = bswap_32(((uint32_t*)st->codec.extradata)[1]);
#endif
st->codec.sub_id = h263_hack_version;
- if((h263_hack_version>>28)==1)
- st->codec.codec_id = CODEC_ID_RV10;
- else
- st->codec.codec_id = CODEC_ID_RV20;
+ switch((h263_hack_version>>28)){
+ case 1: st->codec.codec_id = CODEC_ID_RV10; break;
+ case 2: st->codec.codec_id = CODEC_ID_RV20; break;
+ case 3: st->codec.codec_id = CODEC_ID_RV30; break;
+ case 4: st->codec.codec_id = CODEC_ID_RV40; break;
+ default: goto fail1;
+ }
}
skip:
/* skip codec info */
/* multiple of 20 bytes for ra144 (ugly) */
#define RAW_PACKET_SIZE 1000
+static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){
+ RMContext *rm = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int len, num, res, i;
+ AVStream *st;
+ uint32_t state=0xFFFFFFFF;
+
+ while(!url_feof(pb)){
+ *pos= url_ftell(pb);
+ if(rm->remaining_len > 0){
+ num= rm->current_stream;
+ len= rm->remaining_len;
+ *timestamp = AV_NOPTS_VALUE;
+ *flags= 0;
+ }else{
+ state= (state<<8) + get_byte(pb);
+
+ if(state == MKBETAG('I', 'N', 'D', 'X')){
+ len = get_be16(pb) - 6;
+ if(len<0)
+ continue;
+ goto skip;
+ }
+
+ if(state > (unsigned)0xFFFF || state < 12)
+ continue;
+ len=state;
+ state= 0xFFFFFFFF;
+
+ num = get_be16(pb);
+ *timestamp = get_be32(pb);
+ res= get_byte(pb); /* reserved */
+ *flags = get_byte(pb); /* flags */
+
+
+ len -= 12;
+ }
+ for(i=0;i<s->nb_streams;i++) {
+ st = s->streams[i];
+ if (num == st->id)
+ break;
+ }
+ if (i == s->nb_streams) {
+skip:
+ /* skip packet if unknown number */
+ url_fskip(pb, len);
+ rm->remaining_len -= len;
+ continue;
+ }
+ *stream_index= i;
+
+ return len;
+ }
+ return -1;
+}
+
static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
{
RMContext *rm = s->priv_data;
ByteIOContext *pb = &s->pb;
AVStream *st;
- int num, i, len, tmp, j;
- int64_t timestamp;
+ int i, len, tmp, j;
+ int64_t timestamp, pos;
uint8_t *ptr;
- int flags, res;
+ int flags;
if (rm->old_format) {
/* just read raw bytes */
len = RAW_PACKET_SIZE;
- av_new_packet(pkt, len);
+ len= av_get_packet(pb, pkt, len);
pkt->stream_index = 0;
- len = get_buffer(pb, pkt->data, len);
if (len <= 0) {
- av_free_packet(pkt);
return AVERROR_IO;
}
pkt->size = len;
st = s->streams[0];
} else {
- redo:
- if (url_feof(pb))
+ int seq=1;
+resync:
+ len=sync(s, ×tamp, &flags, &i, &pos);
+ if(len<0)
return AVERROR_IO;
- if(rm->remaining_len > 0){
- num= rm->current_stream;
- len= rm->remaining_len;
- timestamp = AV_NOPTS_VALUE;
- flags= 0;
- }else{
- if(get_byte(pb))
- goto redo;
- if(get_byte(pb))
- goto redo;
- len = get_be16(pb);
- if (len < 12)
- goto redo;
- num = get_be16(pb);
- timestamp = get_be32(pb);
- res= get_byte(pb); /* reserved */
- flags = get_byte(pb); /* flags */
-
-// av_log(s, AV_LOG_DEBUG, "%d %d %X %d\n", num, timestamp, flags, res);
-
- len -= 12;
- }
-
- st = NULL;
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- if (num == st->id)
- break;
- }
- if (i == s->nb_streams) {
- /* skip packet if unknown number */
- url_fskip(pb, len);
- goto redo;
- }
-
+ st = s->streams[i];
+
if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
int h, pic_num, len2, pos;
h= get_byte(pb); len--;
if(!(h & 0x40)){
- int seq = get_byte(pb);
- len--;
+ seq = get_byte(pb); len--;
}
if((h & 0xc0) == 0x40){
len=len2;
rm->remaining_len-= len;
}
+
+ if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
+ || st->discard >= AVDISCARD_ALL){
+ url_fskip(pb, len);
+ goto resync;
+ }
- av_new_packet(pkt, len);
+ av_get_packet(pb, pkt, len);
pkt->stream_index = i;
- get_buffer(pb, pkt->data, len);
#if 0
if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
}
#endif
pkt->pts= timestamp;
- if(flags&2)
+ if(flags&2){
pkt->flags |= PKT_FLAG_KEY;
+ if((seq&0x7F) == 1)
+ av_add_index_entry(st, pos, timestamp, 0, AVINDEX_KEYFRAME);
+ }
}
/* for AC3, needs to swap bytes */
return 0;
}
+static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
+ int64_t *ppos, int64_t pos_limit)
+{
+ RMContext *rm = s->priv_data;
+ int64_t pos, dts;
+ int stream_index2, flags, len, h;
+
+ pos = *ppos;
+
+ if(rm->old_format)
+ return AV_NOPTS_VALUE;
+
+ url_fseek(&s->pb, pos, SEEK_SET);
+ rm->remaining_len=0;
+ for(;;){
+ int seq=1;
+ AVStream *st;
+
+ len=sync(s, &dts, &flags, &stream_index2, &pos);
+ if(len<0)
+ return AV_NOPTS_VALUE;
+
+ st = s->streams[stream_index2];
+ if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
+ h= get_byte(&s->pb); len--;
+ if(!(h & 0x40)){
+ seq = get_byte(&s->pb); len--;
+ }
+ }
+
+ if((flags&2) && (seq&0x7F) == 1){
+// av_log(s, AV_LOG_DEBUG, "%d %d-%d %Ld %d\n", flags, stream_index2, stream_index, dts, seq);
+ av_add_index_entry(st, pos, dts, 0, AVINDEX_KEYFRAME);
+ if(stream_index2 == stream_index)
+ break;
+ }
+
+ url_fskip(&s->pb, len);
+ }
+ *ppos = pos;
+ return dts;
+}
+
static AVInputFormat rm_iformat = {
"rm",
"rm format",
rm_read_header,
rm_read_packet,
rm_read_close,
+ NULL,
+ rm_read_dts,
};
#ifdef CONFIG_ENCODERS