/*
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file h264.c
* H.264 / AVC / MPEG4 part10 codec.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "dsputil.h"
#include "avcodec.h"
#include "mpegvideo.h"
#include "h264.h"
#include "h264data.h"
#include "h264_parser.h"
#include "golomb.h"
#include "rectangle.h"
#include "cabac.h"
#ifdef ARCH_X86
//#include "i386/h264_i386.h"
#endif
//#undef NDEBUG
#include <assert.h>
#include <string.h>
#include "../libavutil/common.h"
/**
* Value of Picture.reference when Picture is not a reference picture, but
* is held for delayed output.
*/
#define DELAYED_PIC_REF 4
static VLC coeff_token_vlc[4];
static VLC_TYPE coeff_token_vlc_tables[520+332+280+256][2];
static const int coeff_token_vlc_tables_size[4]={520,332,280,256};
static VLC chroma_dc_coeff_token_vlc;
static VLC_TYPE chroma_dc_coeff_token_vlc_table[256][2];
static const int chroma_dc_coeff_token_vlc_table_size = 256;
static VLC total_zeros_vlc[15];
static VLC_TYPE total_zeros_vlc_tables[15][512][2];
static const int total_zeros_vlc_tables_size = 512;
static VLC chroma_dc_total_zeros_vlc[3];
static VLC_TYPE chroma_dc_total_zeros_vlc_tables[3][8][2];
static const int chroma_dc_total_zeros_vlc_tables_size = 8;
static VLC run_vlc[6];
static VLC_TYPE run_vlc_tables[6][8][2];
static const int run_vlc_tables_size = 8;
static VLC run7_vlc;
static VLC_TYPE run7_vlc_table[96][2];
static const int run7_vlc_table_size = 96;
static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp);
static void svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc);
static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize);
static void filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize);
static Picture * remove_long(H264Context *h, int i, int ref_mask);
static av_always_inline uint32_t pack16to32(int a, int b){
#ifdef WORDS_BIGENDIAN
return (b&0xFFFF) + (a<<16);
#else
return (a&0xFFFF) + (b<<16);
#endif
}
static const uint8_t rem6[52]={
0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
};
static const uint8_t div6[52]={
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
};
static const int left_block_options[4][8]={
{0,1,2,3,7,10,8,11},
{2,2,3,3,8,11,8,11},
{0,0,1,1,7,10,7,10},
{0,2,0,2,7,10,7,10}
};
static void fill_caches(H264Context *h, int mb_type, int for_deblock){
MpegEncContext * const s = &h->s;
const int mb_xy= h->mb_xy;
int topleft_xy, top_xy, topright_xy, left_xy[2];
int topleft_type, top_type, topright_type, left_type[2];
int * left_block;
int topleft_partition= -1;
int i;
top_xy = mb_xy - (s->mb_stride << FIELD_PICTURE);
//FIXME deblocking could skip the intra and nnz parts.
if(for_deblock && (h->slice_num == 1 || h->slice_table[mb_xy] == h->slice_table[top_xy]) && !FRAME_MBAFF)
return;
/* Wow, what a mess, why didn't they simplify the interlacing & intra
* stuff, I can't imagine that these complex rules are worth it. */
topleft_xy = top_xy - 1;
topright_xy= top_xy + 1;
left_xy[1] = left_xy[0] = mb_xy-1;
left_block = left_block_options[0];
if(FRAME_MBAFF){
const int pair_xy = s->mb_x + (s->mb_y & ~1)*s->mb_stride;
const int top_pair_xy = pair_xy - s->mb_stride;
const int topleft_pair_xy = top_pair_xy - 1;
const int topright_pair_xy = top_pair_xy + 1;
const int topleft_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topleft_pair_xy]);
const int top_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]);
const int topright_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topright_pair_xy]);
const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]);
const int curr_mb_frame_flag = !IS_INTERLACED(mb_type);
const int bottom = (s->mb_y & 1);
// tprintf(s->avctx, "fill_caches: curr_mb_frame_flag:%d, left_mb_frame_flag:%d, topleft_mb_frame_flag:%d, top_mb_frame_flag:%d, topright_mb_frame_flag:%d\n", curr_mb_frame_flag, left_mb_frame_flag, topleft_mb_frame_flag, top_mb_frame_flag, topright_mb_frame_flag);
if (bottom
? !curr_mb_frame_flag // bottom macroblock
: (!curr_mb_frame_flag && !top_mb_frame_flag) // top macroblock
) {
top_xy -= s->mb_stride;
}
if (bottom
? !curr_mb_frame_flag // bottom macroblock
: (!curr_mb_frame_flag && !topleft_mb_frame_flag) // top macroblock
) {
topleft_xy -= s->mb_stride;
} else if(bottom && curr_mb_frame_flag && !left_mb_frame_flag) {
topleft_xy += s->mb_stride;
// take top left mv from the middle of the mb, as opposed to all other modes which use the bottom right partition
topleft_partition = 0;
}
if (bottom
? !curr_mb_frame_flag // bottom macroblock
: (!curr_mb_frame_flag && !topright_mb_frame_flag) // top macroblock
) {
topright_xy -= s->mb_stride;
}
if (left_mb_frame_flag != curr_mb_frame_flag) {
left_xy[1] = left_xy[0] = pair_xy - 1;
if (curr_mb_frame_flag) {
if (bottom) {
left_block = left_block_options[1];
} else {
left_block= left_block_options[2];
}
} else {
left_xy[1] += s->mb_stride;
left_block = left_block_options[3];
}
}
}
h->top_mb_xy = top_xy;
h->left_mb_xy[0] = left_xy[0];
h->left_mb_xy[1] = left_xy[1];
if(for_deblock){
topleft_type = 0;
topright_type = 0;
top_type = h->slice_table[top_xy ] < 0xFFFF ? s->current_picture.mb_type[top_xy] : 0;
left_type[0] = h->slice_table[left_xy[0] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[0]] : 0;
left_type[1] = h->slice_table[left_xy[1] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[1]] : 0;
if(MB_MBAFF && !IS_INTRA(mb_type)){
int list;
for(list=0; list<h->list_count; list++){
//These values where changed for ease of performing MC, we need to change them back
//FIXME maybe we can make MC and loop filter use the same values or prevent
//the MC code from changing ref_cache and rather use a temporary array.
if(USES_LIST(mb_type,list))
没有合适的资源?快使用搜索试试~ 我知道了~
ffmpeg+VC+study
共304个文件
c:160个
h:137个
plg:1个
4星 · 超过85%的资源 需积分: 10 137 下载量 149 浏览量
2011-10-12
21:43:42
上传
评论
收藏 1.88MB RAR 举报
温馨提示
VC与ffmpeg的完美组合,对于学习ffmpeg的朋友会有一定帮助,大家相互学习吧,也欢迎大家批评指正,
资源推荐
资源详情
资源评论
收起资源包目录
ffmpeg+VC+study (304个子文件)
ffmpeg_vc.BCE 23KB
h264.c 316KB
h263.c 220KB
snow.c 185KB
dsputil.c 166KB
vc1.c 156KB
mpegvideo_enc.c 142KB
vorbis_data.c 131KB
swscale_template.c 130KB
swscale.c 110KB
utils_format.c 103KB
rgb2rgb_template.c 101KB
mpegvideo.c 89KB
mpeg12.c 87KB
ffplay.c 86KB
msmpeg4data.c 85KB
imgconvert.c 82KB
mpegaudiodec.c 81KB
mov.c 76KB
utils.c 74KB
msmpeg4.c 62KB
aac.c 60KB
vorbis_dec.c 59KB
ac3dec_data.c 59KB
mjpegdec.c 52KB
rv34.c 50KB
aactab.c 50KB
dca.c 48KB
ac3dec.c 48KB
mpegts.c 46KB
jrevdct.c 44KB
mpegenc.c 43KB
asf.c 42KB
ac3enc.c 41KB
error_resilience.c 40KB
cook.c 40KB
svq3.c 38KB
avidec.c 37KB
h264pred.c 37KB
ratecontrol.c 33KB
raw.c 31KB
wmadec.c 28KB
rmdec.c 28KB
h263dec.c 27KB
rv10.c 26KB
rv40.c 25KB
intrax8.c 24KB
imgconvert_template.c 23KB
mpegtsenc.c 23KB
swscale_altivec_template.c 23KB
vc1data.c 22KB
yuv2rgb_template.c 22KB
yuv2rgb.c 22KB
pcm.c 21KB
aviobuf.c 21KB
riff.c 20KB
avienc.c 20KB
mp3.c 20KB
mpeg.c 18KB
eac3dec.c 18KB
rv40dsp.c 17KB
simple_idct.c 17KB
test_video.c 16KB
jfdctint.c 16KB
cmdutils.c 16KB
opt.c 16KB
rgb2rgb.c 15KB
dv.c 15KB
wmv2dec.c 15KB
isom.c 15KB
des.c 14KB
allcodecs.c 14KB
vc1dsp.c 14KB
oggdec.c 14KB
eval.c 14KB
westwood.c 13KB
wc3movie.c 13KB
intrax8dsp.c 13KB
yuv4mpeg.c 13KB
libdc1394.c 13KB
wma.c 13KB
jpeglsdec.c 12KB
jfdctfst.c 11KB
bitstream.c 11KB
sierravmd.c 11KB
fft.c 11KB
parser.c 10KB
golomb.c 10KB
h261enc.c 9KB
mpeg12data.c 9KB
mpegaudio_parser.c 9KB
ac3tab.c 9KB
audioconvert.c 8KB
mpegaudiodata.c 8KB
vp3dsp.c 8KB
allformats.c 8KB
cabac.c 8KB
ac3.c 8KB
wav.c 8KB
oggparsevorbis.c 7KB
共 304 条
- 1
- 2
- 3
- 4
elleck
- 粉丝: 4
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页