2 * "Real" compatible mux and demux.
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define BUFFER_DURATION 0
26 int packet_total_size;
28 /* codec related output */
31 int nb_frames; /* current frame number */
32 int total_frames; /* total number of frames */
38 StreamInfo streams[2];
39 StreamInfo *audio_stream, *video_stream;
40 int data_pos; /* position of the data after the header */
48 static void put_str(ByteIOContext *s, const char *tag)
50 put_be16(s,strlen(tag));
56 static void put_str8(ByteIOContext *s, const char *tag)
58 put_byte(s, strlen(tag));
64 static void rv10_write_header(AVFormatContext *ctx,
65 int data_size, int index_pos)
67 RMContext *rm = ctx->priv_data;
68 ByteIOContext *s = &ctx->pb;
70 unsigned char *data_offset_ptr, *start_ptr;
71 const char *desc, *mimetype;
72 int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i;
73 int bit_rate, v, duration, flags, data_pos;
75 start_ptr = s->buf_ptr;
78 put_be32(s,18); /* header size */
81 put_be32(s,4 + ctx->nb_streams); /* num headers */
87 packet_total_size = 0;
91 for(i=0;i<ctx->nb_streams;i++) {
92 StreamInfo *stream = &rm->streams[i];
93 bit_rate += stream->bit_rate;
94 if (stream->packet_max_size > packet_max_size)
95 packet_max_size = stream->packet_max_size;
96 nb_packets += stream->nb_packets;
97 packet_total_size += stream->packet_total_size;
98 /* select maximum duration */
99 v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate);
103 put_be32(s, bit_rate); /* max bit rate */
104 put_be32(s, bit_rate); /* avg bit rate */
105 put_be32(s, packet_max_size); /* max packet size */
107 packet_avg_size = packet_total_size / nb_packets;
110 put_be32(s, packet_avg_size); /* avg packet size */
111 put_be32(s, nb_packets); /* num packets */
112 put_be32(s, duration); /* duration */
113 put_be32(s, BUFFER_DURATION); /* preroll */
114 put_be32(s, index_pos); /* index offset */
115 /* computation of data the data offset */
116 data_offset_ptr = s->buf_ptr;
117 put_be32(s, 0); /* data offset : will be patched after */
118 put_be16(s, ctx->nb_streams); /* num streams */
119 flags = 1 | 2; /* save allowed & perfect play */
120 if (url_is_streamed(s))
121 flags |= 4; /* live broadcast */
127 size = strlen(ctx->title) + strlen(ctx->author) + strlen(ctx->copyright) +
128 strlen(ctx->comment) + 4 * 2 + 10;
131 put_str(s, ctx->title);
132 put_str(s, ctx->author);
133 put_str(s, ctx->copyright);
134 put_str(s, ctx->comment);
136 for(i=0;i<ctx->nb_streams;i++) {
139 stream = &rm->streams[i];
141 if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
142 desc = "The Audio Stream";
143 mimetype = "audio/x-pn-realaudio";
144 codec_data_size = 73;
146 desc = "The Video Stream";
147 mimetype = "video/x-pn-realvideo";
148 codec_data_size = 34;
152 size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size;
156 put_be16(s, i); /* stream number */
157 put_be32(s, stream->bit_rate); /* max bit rate */
158 put_be32(s, stream->bit_rate); /* avg bit rate */
159 put_be32(s, stream->packet_max_size); /* max packet size */
160 if (stream->nb_packets > 0)
161 packet_avg_size = stream->packet_total_size /
165 put_be32(s, packet_avg_size); /* avg packet size */
166 put_be32(s, 0); /* start time */
167 put_be32(s, BUFFER_DURATION); /* preroll */
169 if (url_is_streamed(s) || !stream->total_frames)
170 put_be32(s, (int)(3600 * 1000));
172 put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
174 put_str8(s, mimetype);
175 put_be32(s, codec_data_size);
177 if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
178 int coded_frame_size, fscode, sample_rate;
179 sample_rate = stream->enc->sample_rate;
180 coded_frame_size = (stream->enc->bit_rate *
181 stream->enc->frame_size) / (8 * sample_rate);
182 /* audio codec info */
185 put_be32(s, 0x00040000); /* version */
187 put_be32(s, 0x01b53530); /* stream length */
188 put_be16(s, 4); /* unknown */
189 put_be32(s, 0x39); /* header size */
191 switch(sample_rate) {
208 put_be16(s, fscode); /* codec additional info, for AC3, seems
209 to be a frequency code */
210 /* special hack to compensate rounding errors... */
211 if (coded_frame_size == 557)
213 put_be32(s, coded_frame_size); /* frame length */
214 put_be32(s, 0x51540); /* unknown */
215 put_be32(s, 0x249f0); /* unknown */
216 put_be32(s, 0x249f0); /* unknown */
218 /* frame length : seems to be very important */
219 put_be16(s, coded_frame_size);
220 put_be32(s, 0); /* unknown */
221 put_be16(s, stream->enc->sample_rate); /* sample rate */
222 put_be32(s, 0x10); /* unknown */
223 put_be16(s, stream->enc->channels);
224 put_str8(s, "Int0"); /* codec name */
225 put_str8(s, "dnet"); /* codec name */
226 put_be16(s, 0); /* title length */
227 put_be16(s, 0); /* author length */
228 put_be16(s, 0); /* copyright length */
229 put_byte(s, 0); /* end of header */
231 /* video codec info */
232 put_be32(s,34); /* size */
233 if(stream->enc->codec_id == CODEC_ID_RV10)
234 put_tag(s,"VIDORV10");
236 put_tag(s,"VIDORV20");
237 put_be16(s, stream->enc->width);
238 put_be16(s, stream->enc->height);
239 put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */
240 put_be32(s,0); /* unknown meaning */
241 put_be16(s, (int) stream->frame_rate); /* unknown meaning */
242 put_be32(s,0); /* unknown meaning */
243 put_be16(s, 8); /* unknown meaning */
244 /* Seems to be the codec version: only use basic H263. The next
245 versions seems to add a diffential DC coding as in
246 MPEG... nothing new under the sun */
247 if(stream->enc->codec_id == CODEC_ID_RV10)
248 put_be32(s,0x10000000);
250 put_be32(s,0x20103001);
251 //put_be32(s,0x10003000);
255 /* patch data offset field */
256 data_pos = s->buf_ptr - start_ptr;
257 rm->data_pos = data_pos;
258 data_offset_ptr[0] = data_pos >> 24;
259 data_offset_ptr[1] = data_pos >> 16;
260 data_offset_ptr[2] = data_pos >> 8;
261 data_offset_ptr[3] = data_pos;
265 put_be32(s,data_size + 10 + 8);
268 put_be32(s, nb_packets); /* number of packets */
269 put_be32(s,0); /* next data header */
272 static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
273 int length, int key_frame)
276 ByteIOContext *s = &ctx->pb;
278 stream->nb_packets++;
279 stream->packet_total_size += length;
280 if (length > stream->packet_max_size)
281 stream->packet_max_size = length;
283 put_be16(s,0); /* version */
284 put_be16(s,length + 12);
285 put_be16(s, stream->num); /* stream number */
286 timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate;
287 put_be32(s, timestamp); /* timestamp */
288 put_byte(s, 0); /* reserved */
289 put_byte(s, key_frame ? 2 : 0); /* flags */
292 static int rm_write_header(AVFormatContext *s)
294 RMContext *rm = s->priv_data;
297 AVCodecContext *codec;
299 for(n=0;n<s->nb_streams;n++) {
300 s->streams[n]->id = n;
301 codec = s->streams[n]->codec;
302 stream = &rm->streams[n];
303 memset(stream, 0, sizeof(StreamInfo));
305 stream->bit_rate = codec->bit_rate;
308 switch(codec->codec_type) {
309 case CODEC_TYPE_AUDIO:
310 rm->audio_stream = stream;
311 stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
312 /* XXX: dummy values */
313 stream->packet_max_size = 1024;
314 stream->nb_packets = 0;
315 stream->total_frames = stream->nb_packets;
317 case CODEC_TYPE_VIDEO:
318 rm->video_stream = stream;
319 stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num;
320 /* XXX: dummy values */
321 stream->packet_max_size = 4096;
322 stream->nb_packets = 0;
323 stream->total_frames = stream->nb_packets;
330 rv10_write_header(s, 0, 0);
331 put_flush_packet(&s->pb);
335 static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
338 RMContext *rm = s->priv_data;
339 ByteIOContext *pb = &s->pb;
340 StreamInfo *stream = rm->audio_stream;
343 /* XXX: suppress this malloc */
344 buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) );
346 write_packet_header(s, stream, size, !!(flags & PKT_FLAG_KEY));
348 /* for AC3, the words seems to be reversed */
349 for(i=0;i<size;i+=2) {
353 put_buffer(pb, buf1, size);
354 put_flush_packet(pb);
360 static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags)
362 RMContext *rm = s->priv_data;
363 ByteIOContext *pb = &s->pb;
364 StreamInfo *stream = rm->video_stream;
365 int key_frame = !!(flags & PKT_FLAG_KEY);
367 /* XXX: this is incorrect: should be a parameter */
369 /* Well, I spent some time finding the meaning of these bits. I am
370 not sure I understood everything, but it works !! */
372 write_packet_header(s, stream, size + 7, key_frame);
373 /* bit 7: '1' if final packet of a frame converted in several packets */
375 /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
376 frame starting from 1 */
382 put_be16(pb, 0x4000 + (size)); /* total frame size */
383 put_be16(pb, 0x4000 + (size)); /* offset from the start or the end */
386 write_packet_header(s, size + 6);
388 put_be16(pb, 0x4000 + size); /* total frame size */
389 put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
391 put_byte(pb, stream->nb_frames & 0xff);
393 put_buffer(pb, buf, size);
394 put_flush_packet(pb);
400 static int rm_write_packet(AVFormatContext *s, AVPacket *pkt)
402 if (s->streams[pkt->stream_index]->codec->codec_type ==
404 return rm_write_audio(s, pkt->data, pkt->size, pkt->flags);
406 return rm_write_video(s, pkt->data, pkt->size, pkt->flags);
409 static int rm_write_trailer(AVFormatContext *s)
411 RMContext *rm = s->priv_data;
412 int data_size, index_pos, i;
413 ByteIOContext *pb = &s->pb;
415 if (!url_is_streamed(&s->pb)) {
416 /* end of file: finish to write header */
417 index_pos = url_fseek(pb, 0, SEEK_CUR);
418 data_size = index_pos - rm->data_pos;
422 put_be32(pb, 10 + 10 * s->nb_streams);
425 for(i=0;i<s->nb_streams;i++) {
426 put_be32(pb, 0); /* zero indices */
427 put_be16(pb, i); /* stream number */
428 put_be32(pb, 0); /* next index */
430 /* undocumented end header */
434 url_fseek(pb, 0, SEEK_SET);
435 for(i=0;i<s->nb_streams;i++)
436 rm->streams[i].total_frames = rm->streams[i].nb_frames;
437 rv10_write_header(s, data_size, index_pos);
439 /* undocumented end header */
443 put_flush_packet(pb);
446 #endif //CONFIG_MUXERS
448 /***************************************************/
450 static void get_str(ByteIOContext *pb, char *buf, int buf_size)
458 if (i < buf_size - 1)
464 static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
472 if (i < buf_size - 1)
478 static void rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
481 ByteIOContext *pb = &s->pb;
487 version = get_be32(pb); /* version */
488 if (((version >> 16) & 0xff) == 3) {
489 /* very old version */
490 for(i = 0; i < 14; i++)
492 get_str8(pb, s->title, sizeof(s->title));
493 get_str8(pb, s->author, sizeof(s->author));
494 get_str8(pb, s->copyright, sizeof(s->copyright));
495 get_str8(pb, s->comment, sizeof(s->comment));
497 get_str8(pb, buf, sizeof(buf));
498 st->codec->sample_rate = 8000;
499 st->codec->channels = 1;
500 st->codec->codec_type = CODEC_TYPE_AUDIO;
501 st->codec->codec_id = CODEC_ID_RA_144;
503 int flavor, sub_packet_h, coded_framesize;
504 /* old version (4) */
505 get_be32(pb); /* .ra4 */
506 get_be32(pb); /* data size */
507 get_be16(pb); /* version2 */
508 get_be32(pb); /* header size */
509 flavor= get_be16(pb); /* add codec info / flavor */
510 coded_framesize= get_be32(pb); /* coded frame size */
511 get_be32(pb); /* ??? */
512 get_be32(pb); /* ??? */
513 get_be32(pb); /* ??? */
514 sub_packet_h= get_be16(pb); /* 1 */
515 st->codec->block_align= get_be16(pb); /* frame size */
516 get_be16(pb); /* sub packet size */
517 get_be16(pb); /* ??? */
518 st->codec->sample_rate = get_be16(pb);
520 st->codec->channels = get_be16(pb);
521 get_str8(pb, buf, sizeof(buf)); /* desc */
522 get_str8(pb, buf, sizeof(buf)); /* desc */
523 st->codec->codec_type = CODEC_TYPE_AUDIO;
524 if (!strcmp(buf, "dnet")) {
525 st->codec->codec_id = CODEC_ID_AC3;
526 } else if (!strcmp(buf, "28_8")) {
527 st->codec->codec_id = CODEC_ID_RA_288;
528 st->codec->extradata_size= 10;
529 st->codec->extradata= av_mallocz(st->codec->extradata_size);
530 /* this is completly braindead and broken, the idiot who added this codec and endianness
531 specific reordering to mplayer and libavcodec/ra288.c should be drowned in a see of cola */
532 //FIXME pass the unpermutated extradata
533 ((uint16_t*)st->codec->extradata)[1]= sub_packet_h;
534 ((uint16_t*)st->codec->extradata)[2]= flavor;
535 ((uint16_t*)st->codec->extradata)[3]= coded_framesize;
537 st->codec->codec_id = CODEC_ID_NONE;
538 pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name),
546 get_str8(pb, s->title, sizeof(s->title));
547 get_str8(pb, s->author, sizeof(s->author));
548 get_str8(pb, s->copyright, sizeof(s->copyright));
549 get_str8(pb, s->comment, sizeof(s->comment));
554 static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap)
556 RMContext *rm = s->priv_data;
560 st = av_new_stream(s, 0);
563 rm_read_audio_stream_info(s, st, 1);
569 static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
571 RMContext *rm = s->priv_data;
573 ByteIOContext *pb = &s->pb;
575 int tag_size, size, codec_data_size, i;
577 unsigned int h263_hack_version, start_time, duration;
582 if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
583 /* very old .ra format */
584 return rm_read_header_old(s, ap);
585 } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
589 get_be32(pb); /* header size */
592 get_be32(pb); /* number of headers */
598 tag_size = get_be32(pb);
601 printf("tag=%c%c%c%c (%08x) size=%d\n",
609 if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
612 case MKTAG('P', 'R', 'O', 'P'):
614 get_be32(pb); /* max bit rate */
615 get_be32(pb); /* avg bit rate */
616 get_be32(pb); /* max packet size */
617 get_be32(pb); /* avg packet size */
618 get_be32(pb); /* nb packets */
619 get_be32(pb); /* duration */
620 get_be32(pb); /* preroll */
621 get_be32(pb); /* index offset */
622 get_be32(pb); /* data offset */
623 get_be16(pb); /* nb streams */
624 flags = get_be16(pb); /* flags */
626 case MKTAG('C', 'O', 'N', 'T'):
627 get_str(pb, s->title, sizeof(s->title));
628 get_str(pb, s->author, sizeof(s->author));
629 get_str(pb, s->copyright, sizeof(s->copyright));
630 get_str(pb, s->comment, sizeof(s->comment));
632 case MKTAG('M', 'D', 'P', 'R'):
633 st = av_new_stream(s, 0);
636 st->id = get_be16(pb);
637 get_be32(pb); /* max bit rate */
638 st->codec->bit_rate = get_be32(pb); /* bit rate */
639 get_be32(pb); /* max packet size */
640 get_be32(pb); /* avg packet size */
641 start_time = get_be32(pb); /* start time */
642 get_be32(pb); /* preroll */
643 duration = get_be32(pb); /* duration */
644 st->start_time = start_time;
645 st->duration = duration;
646 get_str8(pb, buf, sizeof(buf)); /* desc */
647 get_str8(pb, buf, sizeof(buf)); /* mimetype */
648 codec_data_size = get_be32(pb);
649 codec_pos = url_ftell(pb);
650 st->codec->codec_type = CODEC_TYPE_DATA;
651 av_set_pts_info(st, 64, 1, 1000);
654 if (v == MKTAG(0xfd, 'a', 'r', '.')) {
656 rm_read_audio_stream_info(s, st, 0);
659 if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
661 av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
664 st->codec->codec_tag = get_le32(pb);
665 // av_log(NULL, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0'));
666 if ( st->codec->codec_tag != MKTAG('R', 'V', '1', '0')
667 && st->codec->codec_tag != MKTAG('R', 'V', '2', '0')
668 && st->codec->codec_tag != MKTAG('R', 'V', '3', '0')
669 && st->codec->codec_tag != MKTAG('R', 'V', '4', '0'))
671 st->codec->width = get_be16(pb);
672 st->codec->height = get_be16(pb);
673 st->codec->time_base.num= 1;
675 st->codec->codec_type = CODEC_TYPE_VIDEO;
680 st->codec->extradata_size= codec_data_size - (url_ftell(pb) - codec_pos);
681 st->codec->extradata= av_malloc(st->codec->extradata_size);
682 get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
684 // av_log(NULL, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2);
685 st->codec->time_base.den = fps * st->codec->time_base.num;
686 /* modification of h263 codec version (!) */
687 #ifdef WORDS_BIGENDIAN
688 h263_hack_version = ((uint32_t*)st->codec->extradata)[1];
690 h263_hack_version = bswap_32(((uint32_t*)st->codec->extradata)[1]);
692 st->codec->sub_id = h263_hack_version;
693 switch((h263_hack_version>>28)){
694 case 1: st->codec->codec_id = CODEC_ID_RV10; break;
695 case 2: st->codec->codec_id = CODEC_ID_RV20; break;
696 case 3: st->codec->codec_id = CODEC_ID_RV30; break;
697 case 4: st->codec->codec_id = CODEC_ID_RV40; break;
702 /* skip codec info */
703 size = url_ftell(pb) - codec_pos;
704 url_fskip(pb, codec_data_size - size);
706 case MKTAG('D', 'A', 'T', 'A'):
709 /* unknown tag: skip it */
710 url_fskip(pb, tag_size - 10);
715 rm->nb_packets = get_be32(pb); /* number of packets */
716 if (!rm->nb_packets && (flags & 4))
717 rm->nb_packets = 3600 * 25;
718 get_be32(pb); /* next data header */
722 for(i=0;i<s->nb_streams;i++) {
723 av_free(s->streams[i]);
728 static int get_num(ByteIOContext *pb, int *len)
739 return (n << 16) | n1;
743 /* multiple of 20 bytes for ra144 (ugly) */
744 #define RAW_PACKET_SIZE 1000
746 static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){
747 RMContext *rm = s->priv_data;
748 ByteIOContext *pb = &s->pb;
749 int len, num, res, i;
751 uint32_t state=0xFFFFFFFF;
753 while(!url_feof(pb)){
755 if(rm->remaining_len > 0){
756 num= rm->current_stream;
757 len= rm->remaining_len;
758 *timestamp = AV_NOPTS_VALUE;
761 state= (state<<8) + get_byte(pb);
763 if(state == MKBETAG('I', 'N', 'D', 'X')){
764 len = get_be16(pb) - 6;
770 if(state > (unsigned)0xFFFF || state < 12)
776 *timestamp = get_be32(pb);
777 res= get_byte(pb); /* reserved */
778 *flags = get_byte(pb); /* flags */
783 for(i=0;i<s->nb_streams;i++) {
788 if (i == s->nb_streams) {
790 /* skip packet if unknown number */
792 rm->remaining_len -= len;
802 static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
804 RMContext *rm = s->priv_data;
805 ByteIOContext *pb = &s->pb;
808 int64_t timestamp, pos;
812 if (rm->old_format) {
813 /* just read raw bytes */
814 len = RAW_PACKET_SIZE;
815 len= av_get_packet(pb, pkt, len);
816 pkt->stream_index = 0;
825 len=sync(s, ×tamp, &flags, &i, &pos);
830 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
831 int h, pic_num, len2, pos;
833 h= get_byte(pb); len--;
835 seq = get_byte(pb); len--;
838 if((h & 0xc0) == 0x40){
841 len2 = get_num(pb, &len);
842 pos = get_num(pb, &len);
845 pic_num= get_byte(pb); len--;
846 rm->remaining_len= len;
847 rm->current_stream= st->id;
849 // av_log(NULL, AV_LOG_DEBUG, "%X len:%d pos:%d len2:%d pic_num:%d\n",h, len, pos, len2, pic_num);
852 rm->remaining_len-= len;
855 if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
856 || st->discard >= AVDISCARD_ALL){
861 av_get_packet(pb, pkt, len);
862 pkt->stream_index = i;
865 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
866 if(st->codec->codec_id == CODEC_ID_RV20){
867 int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);
868 av_log(NULL, AV_LOG_DEBUG, "%d %Ld %d\n", timestamp, timestamp*512LL/25, seq);
870 seq |= (timestamp&~0x3FFF);
871 if(seq - timestamp > 0x2000) seq -= 0x4000;
872 if(seq - timestamp < -0x2000) seq += 0x4000;
878 pkt->flags |= PKT_FLAG_KEY;
880 av_add_index_entry(st, pos, timestamp, 0, AVINDEX_KEYFRAME);
884 /* for AC3, needs to swap bytes */
885 if (st->codec->codec_id == CODEC_ID_AC3) {
887 for(j=0;j<len;j+=2) {
897 static int rm_read_close(AVFormatContext *s)
902 static int rm_probe(AVProbeData *p)
904 /* check file header */
905 if (p->buf_size <= 32)
907 if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
908 p->buf[2] == 'M' && p->buf[3] == 'F' &&
909 p->buf[4] == 0 && p->buf[5] == 0) ||
910 (p->buf[0] == '.' && p->buf[1] == 'r' &&
911 p->buf[2] == 'a' && p->buf[3] == 0xfd))
912 return AVPROBE_SCORE_MAX;
917 static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
918 int64_t *ppos, int64_t pos_limit)
920 RMContext *rm = s->priv_data;
922 int stream_index2, flags, len, h;
927 return AV_NOPTS_VALUE;
929 url_fseek(&s->pb, pos, SEEK_SET);
935 len=sync(s, &dts, &flags, &stream_index2, &pos);
937 return AV_NOPTS_VALUE;
939 st = s->streams[stream_index2];
940 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
941 h= get_byte(&s->pb); len--;
943 seq = get_byte(&s->pb); len--;
947 if((flags&2) && (seq&0x7F) == 1){
948 // av_log(s, AV_LOG_DEBUG, "%d %d-%d %Ld %d\n", flags, stream_index2, stream_index, dts, seq);
949 av_add_index_entry(st, pos, dts, 0, AVINDEX_KEYFRAME);
950 if(stream_index2 == stream_index)
954 url_fskip(&s->pb, len);
960 static AVInputFormat rm_iformat = {
973 static AVOutputFormat rm_oformat = {
976 "application/vnd.rn-realmedia",
985 #endif //CONFIG_MUXERS
989 av_register_input_format(&rm_iformat);
991 av_register_output_format(&rm_oformat);
992 #endif //CONFIG_MUXERS