Libav
|
00001 /* 00002 * FLV decoding. 00003 * This file is part of FFmpeg. 00004 * 00005 * FFmpeg is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * FFmpeg is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with FFmpeg; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #include "mpegvideo.h" 00021 #include "h263.h" 00022 #include "flv.h" 00023 00024 void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last){ 00025 int is11 = get_bits1(gb); 00026 *last = get_bits1(gb); 00027 *run = get_bits(gb, 6); 00028 if(is11){ 00029 *level = get_sbits(gb, 11); 00030 } else { 00031 *level = get_sbits(gb, 7); 00032 } 00033 } 00034 00035 int ff_flv_decode_picture_header(MpegEncContext *s) 00036 { 00037 int format, width, height; 00038 00039 /* picture header */ 00040 if (get_bits_long(&s->gb, 17) != 1) { 00041 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); 00042 return -1; 00043 } 00044 format = get_bits(&s->gb, 5); 00045 if (format != 0 && format != 1) { 00046 av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n"); 00047 return -1; 00048 } 00049 s->h263_flv = format+1; 00050 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ 00051 format = get_bits(&s->gb, 3); 00052 switch (format) { 00053 case 0: 00054 width = get_bits(&s->gb, 8); 00055 height = get_bits(&s->gb, 8); 00056 break; 00057 case 1: 00058 width = get_bits(&s->gb, 16); 00059 height = get_bits(&s->gb, 16); 00060 break; 00061 case 2: 00062 width = 352; 00063 height = 288; 00064 break; 00065 case 3: 00066 width = 176; 00067 height = 144; 00068 break; 00069 case 4: 00070 width = 128; 00071 height = 96; 00072 break; 00073 case 5: 00074 width = 320; 00075 height = 240; 00076 break; 00077 case 6: 00078 width = 160; 00079 height = 120; 00080 break; 00081 default: 00082 width = height = 0; 00083 break; 00084 } 00085 if(avcodec_check_dimensions(s->avctx, width, height)) 00086 return -1; 00087 s->width = width; 00088 s->height = height; 00089 00090 s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2); 00091 s->dropable= s->pict_type > FF_P_TYPE; 00092 if (s->dropable) 00093 s->pict_type = FF_P_TYPE; 00094 00095 skip_bits1(&s->gb); /* deblocking flag */ 00096 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); 00097 00098 s->h263_plus = 0; 00099 00100 s->unrestricted_mv = 1; 00101 s->h263_long_vectors = 0; 00102 00103 /* PEI */ 00104 while (get_bits1(&s->gb) != 0) { 00105 skip_bits(&s->gb, 8); 00106 } 00107 s->f_code = 1; 00108 00109 if(s->avctx->debug & FF_DEBUG_PICT_INFO){ 00110 av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", 00111 s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number); 00112 } 00113 00114 s->y_dc_scale_table= 00115 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; 00116 00117 return 0; 00118 } 00119 00120 AVCodec flv_decoder = { 00121 "flv", 00122 AVMEDIA_TYPE_VIDEO, 00123 CODEC_ID_FLV1, 00124 sizeof(MpegEncContext), 00125 ff_h263_decode_init, 00126 NULL, 00127 ff_h263_decode_end, 00128 ff_h263_decode_frame, 00129 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, 00130 .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"), 00131 .pix_fmts= ff_pixfmt_list_420, 00132 };