Mercurial > libavformat.hg
comparison swf.c @ 2308:c12d367e9246 libavformat
cosmetics, indentation
author | bcoudurier |
---|---|
date | Sun, 05 Aug 2007 01:36:31 +0000 |
parents | d5508f387614 |
children | 15c426951f7b |
comparison
equal
deleted
inserted
replaced
2307:d5508f387614 | 2308:c12d367e9246 |
---|---|
185 max_nbits(&nbits, dy); | 185 max_nbits(&nbits, dy); |
186 | 186 |
187 mask = (1 << nbits) - 1; | 187 mask = (1 << nbits) - 1; |
188 put_bits(pb, 4, nbits - 2); /* 16 bits precision */ | 188 put_bits(pb, 4, nbits - 2); /* 16 bits precision */ |
189 if (dx == 0) { | 189 if (dx == 0) { |
190 put_bits(pb, 1, 0); | 190 put_bits(pb, 1, 0); |
191 put_bits(pb, 1, 1); | 191 put_bits(pb, 1, 1); |
192 put_bits(pb, nbits, dy & mask); | 192 put_bits(pb, nbits, dy & mask); |
193 } else if (dy == 0) { | 193 } else if (dy == 0) { |
194 put_bits(pb, 1, 0); | 194 put_bits(pb, 1, 0); |
195 put_bits(pb, 1, 0); | 195 put_bits(pb, 1, 0); |
196 put_bits(pb, nbits, dx & mask); | 196 put_bits(pb, nbits, dx & mask); |
197 } else { | 197 } else { |
198 put_bits(pb, 1, 1); | 198 put_bits(pb, 1, 1); |
199 put_bits(pb, nbits, dx & mask); | 199 put_bits(pb, nbits, dx & mask); |
200 put_bits(pb, nbits, dy & mask); | 200 put_bits(pb, nbits, dy & mask); |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 #define FRAC_BITS 16 | 204 #define FRAC_BITS 16 |
205 | 205 |
334 put_byte(pb, 1); /* one fill style */ | 334 put_byte(pb, 1); /* one fill style */ |
335 put_byte(pb, 0x41); /* clipped bitmap fill */ | 335 put_byte(pb, 0x41); /* clipped bitmap fill */ |
336 put_le16(pb, BITMAP_ID); /* bitmap ID */ | 336 put_le16(pb, BITMAP_ID); /* bitmap ID */ |
337 /* position of the bitmap */ | 337 /* position of the bitmap */ |
338 put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0, | 338 put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0, |
339 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0); | 339 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0); |
340 put_byte(pb, 0); /* no line style */ | 340 put_byte(pb, 0); /* no line style */ |
341 | 341 |
342 /* shape drawing */ | 342 /* shape drawing */ |
343 init_put_bits(&p, buf1, sizeof(buf1)); | 343 init_put_bits(&p, buf1, sizeof(buf1)); |
344 put_bits(&p, 4, 1); /* one fill bit */ | 344 put_bits(&p, 4, 1); /* one fill bit */ |
414 /* Flash Player limit */ | 414 /* Flash Player limit */ |
415 if ( swf->swf_frame_number == 16000 ) { | 415 if ( swf->swf_frame_number == 16000 ) { |
416 av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); | 416 av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); |
417 } | 417 } |
418 | 418 |
419 if ( swf->video_type == CODEC_ID_VP6F || | 419 if ( swf->video_type == CODEC_ID_VP6F || |
420 swf->video_type == CODEC_ID_FLV1 ) { | 420 swf->video_type == CODEC_ID_FLV1 ) { |
421 if ( swf->video_frame_number == 0 ) { | 421 if ( swf->video_frame_number == 0 ) { |
422 /* create a new video object */ | 422 /* create a new video object */ |
423 put_swf_tag(s, TAG_VIDEOSTREAM); | 423 put_swf_tag(s, TAG_VIDEOSTREAM); |
424 put_le16(pb, VIDEO_ID); | 424 put_le16(pb, VIDEO_ID); |
425 put_le16(pb, 15000 ); /* hard flash player limit */ | 425 put_le16(pb, 15000 ); /* hard flash player limit */ |
426 put_le16(pb, enc->width); | 426 put_le16(pb, enc->width); |
427 put_le16(pb, enc->height); | 427 put_le16(pb, enc->height); |
428 put_byte(pb, 0); | 428 put_byte(pb, 0); |
429 put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type)); | 429 put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type)); |
430 put_swf_end_tag(s); | 430 put_swf_end_tag(s); |
431 | 431 |
432 /* place the video object for the first time */ | 432 /* place the video object for the first time */ |
433 put_swf_tag(s, TAG_PLACEOBJECT2); | 433 put_swf_tag(s, TAG_PLACEOBJECT2); |
434 put_byte(pb, 0x36); | 434 put_byte(pb, 0x36); |
435 put_le16(pb, 1); | 435 put_le16(pb, 1); |
436 put_le16(pb, VIDEO_ID); | 436 put_le16(pb, VIDEO_ID); |
437 put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0); | 437 put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0); |
438 put_le16(pb, swf->video_frame_number ); | 438 put_le16(pb, swf->video_frame_number ); |
439 put_byte(pb, 'v'); | 439 put_byte(pb, 'v'); |
440 put_byte(pb, 'i'); | 440 put_byte(pb, 'i'); |
441 put_byte(pb, 'd'); | 441 put_byte(pb, 'd'); |
442 put_byte(pb, 'e'); | 442 put_byte(pb, 'e'); |
443 put_byte(pb, 'o'); | 443 put_byte(pb, 'o'); |
444 put_byte(pb, 0x00); | 444 put_byte(pb, 0x00); |
445 put_swf_end_tag(s); | 445 put_swf_end_tag(s); |
446 } else { | 446 } else { |
447 /* mark the character for update */ | 447 /* mark the character for update */ |
448 put_swf_tag(s, TAG_PLACEOBJECT2); | 448 put_swf_tag(s, TAG_PLACEOBJECT2); |
449 put_byte(pb, 0x11); | 449 put_byte(pb, 0x11); |
450 put_le16(pb, 1); | 450 put_le16(pb, 1); |
451 put_le16(pb, swf->video_frame_number ); | 451 put_le16(pb, swf->video_frame_number ); |
452 put_swf_end_tag(s); | 452 put_swf_end_tag(s); |
453 } | 453 } |
454 | 454 |
455 /* set video frame data */ | 455 /* set video frame data */ |
456 put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG); | 456 put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG); |
457 put_le16(pb, VIDEO_ID); | 457 put_le16(pb, VIDEO_ID); |
458 put_le16(pb, swf->video_frame_number++ ); | 458 put_le16(pb, swf->video_frame_number++ ); |
459 put_buffer(pb, buf, size); | 459 put_buffer(pb, buf, size); |
460 put_swf_end_tag(s); | 460 put_swf_end_tag(s); |
461 } else if ( swf->video_type == CODEC_ID_MJPEG ) { | 461 } else if ( swf->video_type == CODEC_ID_MJPEG ) { |
462 if (swf->swf_frame_number > 0) { | 462 if (swf->swf_frame_number > 0) { |
463 /* remove the shape */ | 463 /* remove the shape */ |
464 put_swf_tag(s, TAG_REMOVEOBJECT); | 464 put_swf_tag(s, TAG_REMOVEOBJECT); |
465 put_le16(pb, SHAPE_ID); /* shape ID */ | 465 put_le16(pb, SHAPE_ID); /* shape ID */ |
466 put_le16(pb, 1); /* depth */ | 466 put_le16(pb, 1); /* depth */ |
467 put_swf_end_tag(s); | 467 put_swf_end_tag(s); |
468 | 468 |
469 /* free the bitmap */ | 469 /* free the bitmap */ |
470 put_swf_tag(s, TAG_FREECHARACTER); | 470 put_swf_tag(s, TAG_FREECHARACTER); |
471 put_le16(pb, BITMAP_ID); | 471 put_le16(pb, BITMAP_ID); |
472 put_swf_end_tag(s); | 472 put_swf_end_tag(s); |
473 } | 473 } |
474 | 474 |
475 put_swf_tag(s, TAG_JPEG2 | TAG_LONG); | 475 put_swf_tag(s, TAG_JPEG2 | TAG_LONG); |
476 | 476 |
477 put_le16(pb, BITMAP_ID); /* ID of the image */ | 477 put_le16(pb, BITMAP_ID); /* ID of the image */ |
478 | 478 |
479 /* a dummy jpeg header seems to be required */ | 479 /* a dummy jpeg header seems to be required */ |
480 put_byte(pb, 0xff); | 480 put_byte(pb, 0xff); |
481 put_byte(pb, 0xd8); | 481 put_byte(pb, 0xd8); |
482 put_byte(pb, 0xff); | 482 put_byte(pb, 0xff); |
483 put_byte(pb, 0xd9); | 483 put_byte(pb, 0xd9); |
484 /* write the jpeg image */ | 484 /* write the jpeg image */ |
485 put_buffer(pb, buf, size); | 485 put_buffer(pb, buf, size); |
486 | 486 |
487 put_swf_end_tag(s); | 487 put_swf_end_tag(s); |
488 | 488 |
489 /* draw the shape */ | 489 /* draw the shape */ |
490 | 490 |
491 put_swf_tag(s, TAG_PLACEOBJECT); | 491 put_swf_tag(s, TAG_PLACEOBJECT); |
492 put_le16(pb, SHAPE_ID); /* shape ID */ | 492 put_le16(pb, SHAPE_ID); /* shape ID */ |
493 put_le16(pb, 1); /* depth */ | 493 put_le16(pb, 1); /* depth */ |
494 put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0); | 494 put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0); |
495 put_swf_end_tag(s); | 495 put_swf_end_tag(s); |
496 } else { | 496 } else { |
497 /* invalid codec */ | 497 /* invalid codec */ |
498 } | 498 } |
499 | 499 |
500 swf->swf_frame_number ++; | 500 swf->swf_frame_number ++; |
501 | 501 |
502 /* streaming sound always should be placed just before showframe tags */ | 502 /* streaming sound always should be placed just before showframe tags */ |
503 if (swf->audio_type && swf->audio_in_pos) { | 503 if (swf->audio_type && swf->audio_in_pos) { |
504 put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG); | 504 put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG); |
505 put_le16(pb, swf->sound_samples); | 505 put_le16(pb, swf->sound_samples); |
696 if (!sample_rate_code) | 696 if (!sample_rate_code) |
697 return AVERROR(EIO); | 697 return AVERROR(EIO); |
698 ast->codec->sample_rate = 11025 << (sample_rate_code-1); | 698 ast->codec->sample_rate = 11025 << (sample_rate_code-1); |
699 av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); | 699 av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); |
700 len -= 4; | 700 len -= 4; |
701 } else | 701 } else if (tag == TAG_VIDEOFRAME) { |
702 if (tag == TAG_VIDEOFRAME) { | |
703 int ch_id = get_le16(pb); | 702 int ch_id = get_le16(pb); |
704 len -= 2; | 703 len -= 2; |
705 for( i=0; i<s->nb_streams; i++ ) { | 704 for( i=0; i<s->nb_streams; i++ ) { |
706 st = s->streams[i]; | 705 st = s->streams[i]; |
707 if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) { | 706 if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) { |
734 vst->codec->codec_id = CODEC_ID_MJPEG; | 733 vst->codec->codec_id = CODEC_ID_MJPEG; |
735 av_set_pts_info(vst, 64, 256, swf->frame_rate); | 734 av_set_pts_info(vst, 64, 256, swf->frame_rate); |
736 vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; | 735 vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; |
737 st = vst; | 736 st = vst; |
738 } | 737 } |
739 get_le16(pb); /* BITMAP_ID */ | 738 get_le16(pb); /* BITMAP_ID */ |
740 av_new_packet(pkt, len-2); | 739 av_new_packet(pkt, len-2); |
741 get_buffer(pb, pkt->data, 4); | 740 get_buffer(pb, pkt->data, 4); |
742 if (AV_RB32(pkt->data) == 0xffd8ffd9) { | 741 if (AV_RB32(pkt->data) == 0xffd8ffd9) { |
743 /* old SWF files containing SOI/EOI as data start */ | 742 /* old SWF files containing SOI/EOI as data start */ |
744 pkt->size -= 4; | 743 pkt->size -= 4; |
745 get_buffer(pb, pkt->data, pkt->size); | 744 get_buffer(pb, pkt->data, pkt->size); |
746 } else { | 745 } else { |
747 get_buffer(pb, pkt->data + 4, pkt->size - 4); | 746 get_buffer(pb, pkt->data + 4, pkt->size - 4); |
748 } | 747 } |
749 pkt->stream_index = st->index; | 748 pkt->stream_index = st->index; |
750 return pkt->size; | 749 return pkt->size; |
751 } | 750 } |
752 url_fskip(pb, len); | 751 url_fskip(pb, len); |
753 } | 752 } |
754 return 0; | 753 return 0; |
755 } | 754 } |
756 | 755 |
757 static int swf_read_close(AVFormatContext *s) | 756 static int swf_read_close(AVFormatContext *s) |
758 { | 757 { |
759 return 0; | 758 return 0; |
760 } | 759 } |
761 | 760 |
762 #ifdef CONFIG_SWF_DEMUXER | 761 #ifdef CONFIG_SWF_DEMUXER |
763 AVInputFormat swf_demuxer = { | 762 AVInputFormat swf_demuxer = { |
764 "swf", | 763 "swf", |