372
380
write_packet_header(s, stream, size + 7, key_frame);
373
381
/* bit 7: '1' if final packet of a frame converted in several packets */
375
383
/* bit 7: '1' if I frame. bits 6..0 : sequence number in current
376
384
frame starting from 1 */
382
390
put_be16(pb, 0x4000 + (size)); /* total frame size */
383
391
put_be16(pb, 0x4000 + (size)); /* offset from the start or the end */
386
394
write_packet_header(s, size + 6);
388
396
put_be16(pb, 0x4000 + size); /* total frame size */
389
397
put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
391
put_byte(pb, stream->nb_frames & 0xff);
399
put_byte(pb, stream->nb_frames & 0xff);
393
401
put_buffer(pb, buf, size);
394
402
put_flush_packet(pb);
493
503
get_str8(pb, s->author, sizeof(s->author));
494
504
get_str8(pb, s->copyright, sizeof(s->copyright));
495
505
get_str8(pb, s->comment, sizeof(s->comment));
506
if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) {
507
// fourcc (should always be "lpcJ")
497
509
get_str8(pb, buf, sizeof(buf));
511
// Skip extra header crap (this should never happen)
512
if ((startpos + (version & 0xffff)) > url_ftell(pb))
513
url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb));
498
514
st->codec->sample_rate = 8000;
499
515
st->codec->channels = 1;
500
516
st->codec->codec_type = CODEC_TYPE_AUDIO;
501
517
st->codec->codec_id = CODEC_ID_RA_144;
503
int flavor, sub_packet_h, coded_framesize;
519
int flavor, sub_packet_h, coded_framesize, sub_packet_size;
504
520
/* old version (4) */
505
521
get_be32(pb); /* .ra4 */
506
522
get_be32(pb); /* data size */
507
523
get_be16(pb); /* version2 */
508
524
get_be32(pb); /* header size */
509
525
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 */
526
rm->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */
527
get_be32(pb); /* ??? */
528
get_be32(pb); /* ??? */
529
get_be32(pb); /* ??? */
530
rm->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */
515
531
st->codec->block_align= get_be16(pb); /* frame size */
516
get_be16(pb); /* sub packet size */
532
rm->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */
517
533
get_be16(pb); /* ??? */
534
if (((version >> 16) & 0xff) == 5) {
535
get_be16(pb); get_be16(pb); get_be16(pb); }
518
536
st->codec->sample_rate = get_be16(pb);
520
538
st->codec->channels = get_be16(pb);
521
get_str8(pb, buf, sizeof(buf)); /* desc */
522
get_str8(pb, buf, sizeof(buf)); /* desc */
539
if (((version >> 16) & 0xff) == 5) {
541
buf[0] = get_byte(pb);
542
buf[1] = get_byte(pb);
543
buf[2] = get_byte(pb);
544
buf[3] = get_byte(pb);
547
get_str8(pb, buf, sizeof(buf)); /* desc */
548
get_str8(pb, buf, sizeof(buf)); /* desc */
523
550
st->codec->codec_type = CODEC_TYPE_AUDIO;
524
551
if (!strcmp(buf, "dnet")) {
525
552
st->codec->codec_id = CODEC_ID_AC3;
526
553
} else if (!strcmp(buf, "28_8")) {
527
554
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;
555
st->codec->extradata_size= 0;
556
rm->audio_framesize = st->codec->block_align;
557
st->codec->block_align = coded_framesize;
558
rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
559
} else if (!strcmp(buf, "cook")) {
560
int codecdata_length, i;
561
get_be16(pb); get_byte(pb);
562
if (((version >> 16) & 0xff) == 5)
564
codecdata_length = get_be32(pb);
565
st->codec->codec_id = CODEC_ID_COOK;
566
st->codec->extradata_size= codecdata_length;
567
st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
568
for(i = 0; i < codecdata_length; i++)
569
((uint8_t*)st->codec->extradata)[i] = get_byte(pb);
570
rm->audio_framesize = st->codec->block_align;
571
st->codec->block_align = rm->sub_packet_size;
572
rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
537
574
st->codec->codec_id = CODEC_ID_NONE;
538
575
pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name),
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;
849
if (rm->audio_pkt_cnt) {
850
// If there are queued audio packet return them first
851
st = s->streams[rm->audio_stream_num];
852
av_new_packet(pkt, st->codec->block_align);
853
memcpy(pkt->data, rm->audiobuf + st->codec->block_align *
854
(rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
855
st->codec->block_align);
858
pkt->stream_index = rm->audio_stream_num;
859
} else if (rm->old_format) {
821
860
st = s->streams[0];
861
if (st->codec->codec_id == CODEC_ID_RA_288) {
864
for (y = 0; y < rm->sub_packet_h; y++)
865
for (x = 0; x < rm->sub_packet_h/2; x++)
866
if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0)
868
rm->audio_stream_num = 0;
869
rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1;
870
// Release first audio packet
871
av_new_packet(pkt, st->codec->block_align);
872
memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
873
pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe
874
pkt->stream_index = 0;
876
/* just read raw bytes */
877
len = RAW_PACKET_SIZE;
878
len= av_get_packet(pb, pkt, len);
879
pkt->stream_index = 0;
850
913
if(len2 && len2<len)
852
915
rm->remaining_len-= len;
916
av_get_packet(pb, pkt, len);
919
if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
920
if ((st->codec->codec_id == CODEC_ID_RA_288) ||
921
(st->codec->codec_id == CODEC_ID_COOK)) {
923
int sps = rm->sub_packet_size;
924
int cfs = rm->coded_framesize;
925
int h = rm->sub_packet_h;
926
int y = rm->sub_packet_cnt;
927
int w = rm->audio_framesize;
930
y = rm->sub_packet_cnt = 0;
932
rm->audiotimestamp = timestamp;
934
switch(st->codec->codec_id) {
935
case CODEC_ID_RA_288:
936
for (x = 0; x < h/2; x++)
937
get_buffer(pb, rm->audiobuf+x*2*w+y*cfs, cfs);
940
for (x = 0; x < w/sps; x++)
941
get_buffer(pb, rm->audiobuf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
945
if (++(rm->sub_packet_cnt) < h)
948
rm->sub_packet_cnt = 0;
949
rm->audio_stream_num = i;
950
rm->audio_pkt_cnt = h * w / st->codec->block_align - 1;
951
// Release first audio packet
952
av_new_packet(pkt, st->codec->block_align);
953
memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
954
timestamp = rm->audiotimestamp;
955
flags = 2; // Mark first packet as keyframe
958
av_get_packet(pb, pkt, len);
855
961
if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
856
962
|| st->discard >= AVDISCARD_ALL){
861
av_get_packet(pb, pkt, len);
862
967
pkt->stream_index = i;