comparison mjpeg.c @ 2370:26560d4fdb1f libavcodec

Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
author michael
date Sat, 27 Nov 2004 18:10:06 +0000
parents c353719836af
children 18b8b2dcc037
comparison
equal deleted inserted replaced
2369:ce47b1d51cb1 2370:26560d4fdb1f
842 } MJpegDecodeContext; 842 } MJpegDecodeContext;
843 843
844 static int mjpeg_decode_dht(MJpegDecodeContext *s); 844 static int mjpeg_decode_dht(MJpegDecodeContext *s);
845 845
846 static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, 846 static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
847 int nb_codes) 847 int nb_codes, int use_static)
848 { 848 {
849 uint8_t huff_size[256]; 849 uint8_t huff_size[256];
850 uint16_t huff_code[256]; 850 uint16_t huff_code[256];
851 851
852 memset(huff_size, 0, sizeof(huff_size)); 852 memset(huff_size, 0, sizeof(huff_size));
853 build_huffman_codes(huff_size, huff_code, bits_table, val_table); 853 build_huffman_codes(huff_size, huff_code, bits_table, val_table);
854 854
855 return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2); 855 return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static);
856 } 856 }
857 857
858 static int mjpeg_decode_init(AVCodecContext *avctx) 858 static int mjpeg_decode_init(AVCodecContext *avctx)
859 { 859 {
860 MJpegDecodeContext *s = avctx->priv_data; 860 MJpegDecodeContext *s = avctx->priv_data;
880 return -1; 880 return -1;
881 s->start_code = -1; 881 s->start_code = -1;
882 s->first_picture = 1; 882 s->first_picture = 1;
883 s->org_height = avctx->coded_height; 883 s->org_height = avctx->coded_height;
884 884
885 build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12); 885 build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12, 0);
886 build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12); 886 build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12, 0);
887 build_vlc(&s->vlcs[1][0], bits_ac_luminance, val_ac_luminance, 251); 887 build_vlc(&s->vlcs[1][0], bits_ac_luminance, val_ac_luminance, 251, 0);
888 build_vlc(&s->vlcs[1][1], bits_ac_chrominance, val_ac_chrominance, 251); 888 build_vlc(&s->vlcs[1][1], bits_ac_chrominance, val_ac_chrominance, 251, 0);
889 889
890 if (avctx->flags & CODEC_FLAG_EXTERN_HUFF) 890 if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
891 { 891 {
892 av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n"); 892 av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
893 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); 893 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
1034 1034
1035 /* build VLC and flush previous vlc if present */ 1035 /* build VLC and flush previous vlc if present */
1036 free_vlc(&s->vlcs[class][index]); 1036 free_vlc(&s->vlcs[class][index]);
1037 dprintf("class=%d index=%d nb_codes=%d\n", 1037 dprintf("class=%d index=%d nb_codes=%d\n",
1038 class, index, code_max + 1); 1038 class, index, code_max + 1);
1039 if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1) < 0){ 1039 if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1, 0) < 0){
1040 return -1; 1040 return -1;
1041 } 1041 }
1042 } 1042 }
1043 return 0; 1043 return 0;
1044 } 1044 }