comparison swf.c @ 820:feca73904e67 libavformat

changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
author michael
date Sun, 17 Jul 2005 22:24:36 +0000
parents 2b09fa58db70
children 66cc656ea404
comparison
equal deleted inserted replaced
819:a6c035e7f429 820:feca73904e67
322 swf->video_frame_number = 0; 322 swf->video_frame_number = 0;
323 323
324 video_enc = NULL; 324 video_enc = NULL;
325 audio_enc = NULL; 325 audio_enc = NULL;
326 for(i=0;i<s->nb_streams;i++) { 326 for(i=0;i<s->nb_streams;i++) {
327 enc = &s->streams[i]->codec; 327 enc = s->streams[i]->codec;
328 if (enc->codec_type == CODEC_TYPE_AUDIO) 328 if (enc->codec_type == CODEC_TYPE_AUDIO)
329 audio_enc = enc; 329 audio_enc = enc;
330 else { 330 else {
331 if ( enc->codec_id == CODEC_ID_FLV1 || enc->codec_id == CODEC_ID_MJPEG ) { 331 if ( enc->codec_id == CODEC_ID_FLV1 || enc->codec_id == CODEC_ID_MJPEG ) {
332 video_enc = enc; 332 video_enc = enc;
650 return 0; 650 return 0;
651 } 651 }
652 652
653 static int swf_write_packet(AVFormatContext *s, AVPacket *pkt) 653 static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
654 { 654 {
655 AVCodecContext *codec = &s->streams[pkt->stream_index]->codec; 655 AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
656 if (codec->codec_type == CODEC_TYPE_AUDIO) 656 if (codec->codec_type == CODEC_TYPE_AUDIO)
657 return swf_write_audio(s, codec, pkt->data, pkt->size); 657 return swf_write_audio(s, codec, pkt->data, pkt->size);
658 else 658 else
659 return swf_write_video(s, codec, pkt->data, pkt->size); 659 return swf_write_video(s, codec, pkt->data, pkt->size);
660 } 660 }
666 AVCodecContext *enc, *video_enc; 666 AVCodecContext *enc, *video_enc;
667 int file_size, i; 667 int file_size, i;
668 668
669 video_enc = NULL; 669 video_enc = NULL;
670 for(i=0;i<s->nb_streams;i++) { 670 for(i=0;i<s->nb_streams;i++) {
671 enc = &s->streams[i]->codec; 671 enc = s->streams[i]->codec;
672 if (enc->codec_type == CODEC_TYPE_VIDEO) 672 if (enc->codec_type == CODEC_TYPE_VIDEO)
673 video_enc = enc; 673 video_enc = enc;
674 } 674 }
675 675
676 put_swf_tag(s, TAG_END); 676 put_swf_tag(s, TAG_END);
773 for(;;) { 773 for(;;) {
774 tag = get_swf_tag(pb, &len); 774 tag = get_swf_tag(pb, &len);
775 if (tag < 0) { 775 if (tag < 0) {
776 if ( ast || vst ) { 776 if ( ast || vst ) {
777 if ( vst && ast ) { 777 if ( vst && ast ) {
778 vst->codec.time_base.den = ast->codec.sample_rate / swf->samples_per_frame; 778 vst->codec->time_base.den = ast->codec->sample_rate / swf->samples_per_frame;
779 vst->codec.time_base.num = 1; 779 vst->codec->time_base.num = 1;
780 } 780 }
781 break; 781 break;
782 } 782 }
783 av_log(s, AV_LOG_ERROR, "No media found in SWF\n"); 783 av_log(s, AV_LOG_ERROR, "No media found in SWF\n");
784 return AVERROR_IO; 784 return AVERROR_IO;
792 /* Check for FLV1 */ 792 /* Check for FLV1 */
793 if ( get_byte(pb) == SWF_VIDEO_CODEC_FLV1 ) { 793 if ( get_byte(pb) == SWF_VIDEO_CODEC_FLV1 ) {
794 vst = av_new_stream(s, 0); 794 vst = av_new_stream(s, 0);
795 av_set_pts_info(vst, 24, 1, 1000); /* 24 bit pts in ms */ 795 av_set_pts_info(vst, 24, 1, 1000); /* 24 bit pts in ms */
796 796
797 vst->codec.codec_type = CODEC_TYPE_VIDEO; 797 vst->codec->codec_type = CODEC_TYPE_VIDEO;
798 vst->codec.codec_id = CODEC_ID_FLV1; 798 vst->codec->codec_id = CODEC_ID_FLV1;
799 if ( swf->samples_per_frame ) { 799 if ( swf->samples_per_frame ) {
800 vst->codec.time_base.den = 1000. / swf->ms_per_frame; 800 vst->codec->time_base.den = 1000. / swf->ms_per_frame;
801 vst->codec.time_base.num = 1; 801 vst->codec->time_base.num = 1;
802 } 802 }
803 } 803 }
804 } else if ( ( tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2 ) && !ast) { 804 } else if ( ( tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2 ) && !ast) {
805 /* streaming found */ 805 /* streaming found */
806 get_byte(pb); 806 get_byte(pb);
817 av_set_pts_info(ast, 24, 1, 1000); /* 24 bit pts in ms */ 817 av_set_pts_info(ast, 24, 1, 1000); /* 24 bit pts in ms */
818 if (!ast) 818 if (!ast)
819 return -ENOMEM; 819 return -ENOMEM;
820 820
821 if (v & 0x01) 821 if (v & 0x01)
822 ast->codec.channels = 2; 822 ast->codec->channels = 2;
823 else 823 else
824 ast->codec.channels = 1; 824 ast->codec->channels = 1;
825 825
826 switch((v>> 2) & 0x03) { 826 switch((v>> 2) & 0x03) {
827 case 1: 827 case 1:
828 ast->codec.sample_rate = 11025; 828 ast->codec->sample_rate = 11025;
829 break; 829 break;
830 case 2: 830 case 2:
831 ast->codec.sample_rate = 22050; 831 ast->codec->sample_rate = 22050;
832 break; 832 break;
833 case 3: 833 case 3:
834 ast->codec.sample_rate = 44100; 834 ast->codec->sample_rate = 44100;
835 break; 835 break;
836 default: 836 default:
837 av_free(ast); 837 av_free(ast);
838 return AVERROR_IO; 838 return AVERROR_IO;
839 } 839 }
840 ast->codec.codec_type = CODEC_TYPE_AUDIO; 840 ast->codec->codec_type = CODEC_TYPE_AUDIO;
841 ast->codec.codec_id = CODEC_ID_MP3; 841 ast->codec->codec_id = CODEC_ID_MP3;
842 } 842 }
843 } else { 843 } else {
844 url_fskip(pb, len); 844 url_fskip(pb, len);
845 } 845 }
846 } 846 }