📄 mpegvideo.c
字号:
yc_size = y_size + 2 * c_size;
/* convert fourcc to upper case */
s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF)
+ (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 )
+ (toupper((s->avctx->codec_tag>>16)&0xFF)<<16)
+ (toupper((s->avctx->codec_tag>>24)&0xFF)<<24);
s->avctx->stream_codec_tag= toupper( s->avctx->stream_codec_tag &0xFF)
+ (toupper((s->avctx->stream_codec_tag>>8 )&0xFF)<<8 )
+ (toupper((s->avctx->stream_codec_tag>>16)&0xFF)<<16)
+ (toupper((s->avctx->stream_codec_tag>>24)&0xFF)<<24);
CHECKED_ALLOCZ(s->mb_index2xy, (s->mb_num+1)*sizeof(int)) //error ressilience code looks cleaner with this
for(y=0; y<s->mb_height; y++){
for(x=0; x<s->mb_width; x++){
s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;
}
}
s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed?
CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture))
CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t))
//Note the +1 is for a quicker mpeg4 slice_end detection
CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE);
s->context_initialized = 1;
s->thread_context[0]= s;
if(init_duplicate_context(s->thread_context[0], s) < 0)
goto fail;
return 0;
fail:
MPV_common_end(s);
return -1;
}
/* init common structure for both encoder and decoder */
void MPV_common_end(MpegEncContext *s)
{
int i;
free_duplicate_context(s->thread_context[0]);
av_freep(&s->mb_type);
av_freep(&s->cbp_table);
av_freep(&s->prev_pict_types);
av_freep(&s->error_status_table);
av_freep(&s->mb_index2xy);
if(s->picture){
for(i=0; i<MAX_PICTURE_COUNT; i++){
free_picture(s, &s->picture[i]);
}
}
av_freep(&s->picture);
s->context_initialized = 0;
s->last_picture_ptr=
s->next_picture_ptr=
s->current_picture_ptr= NULL;
s->linesize= s->uvlinesize= 0;
}
/* draw the edges of width 'w' of an image of size width, height */
//FIXME check that this is ok for mpeg4 interlaced
STATIC_FUNC void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
{
uint8_t *ptr, *last_line;
int i;
last_line = buf + (height - 1) * wrap;
for(i=0;i<w;i++) {
/* top and bottom */
MEMCPY(buf - (i + 1) * wrap, buf, width);
MEMCPY(last_line + (i + 1) * wrap, last_line, width);
}
/* left and right */
ptr = buf;
for(i=0;i<height;i++) {
memset(ptr - w, ptr[0], w);
memset(ptr + width, ptr[width-1], w);
ptr += wrap;
}
/* corners */
for(i=0;i<w;i++) {
memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
}
}
int ff_find_unused_picture(MpegEncContext *s, int shared){
int i;
if(shared){
for(i=0; i<MAX_PICTURE_COUNT; i++){
if(s->picture[i].data[0]==NULL && s->picture[i].type==0) return i;
}
}else{
// for(i=0; i<MAX_PICTURE_COUNT; i++){
// if(s->picture[i].data[0]==NULL && s->picture[i].type!=0) return i; //FIXME
// }
for(i=0; i<MAX_PICTURE_COUNT; i++){
if(s->picture[i].data[0]==NULL) return i;
}
}
assert(0);
return -1;
}
/**
* generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded
*/
int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
{
int i;
AVFrame *pic;
assert(s->last_picture_ptr==NULL);
//alloc:
/* release non reference frames */
for(i=0; i<MAX_PICTURE_COUNT; i++){
if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
}
}
if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL)
pic= (AVFrame*)s->current_picture_ptr; //we allready have a unused image (maybe it was set before reading the header)
else{
i= ff_find_unused_picture(s, 0);
pic= (AVFrame*)&s->picture[i];
}
pic->reference= (s->pict_type != B_TYPE || s->codec_id == CODEC_ID_H264)
&& !s->dropable ? 3 : 0;
// (Picture*)pic->data[0]=s->current_picture.data[0];
DP_DEC((M_TEXT("In MPV_frame_start\n")));
if( alloc_picture(s, (Picture*)pic, 0) < 0)
return -1;
s->current_picture_ptr= (Picture*)pic;
s->current_picture_ptr->interlaced_frame= 0;
s->current_picture_ptr->pict_type= s->pict_type;
s->current_picture_ptr->key_frame= s->pict_type == I_TYPE;
copy_picture(&s->current_picture, s->current_picture_ptr);
s->error_resilience= avctx->error_resilience;
return 0;
}
/**
* Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples.
* @param buf destination buffer
* @param src source buffer
* @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
* @param block_w width of block
* @param block_h height of block
* @param src_x x coordinate of the top left sample of the block in the source buffer
* @param src_y y coordinate of the top left sample of the block in the source buffer
* @param w width of the source buffer
* @param h height of the source buffer
*/
void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
int src_x, int src_y, int w, int h){
int x, y;
int start_y, start_x, end_y, end_x;
if(src_y>= h){
src+= (h-1-src_y)*linesize;
src_y=h-1;
}else if(src_y<=-block_h){
src+= (1-block_h-src_y)*linesize;
src_y=1-block_h;
}
if(src_x>= w){
src+= (w-1-src_x);
src_x=w-1;
}else if(src_x<=-block_w){
src+= (1-block_w-src_x);
src_x=1-block_w;
}
start_y= FFMAX(0, -src_y);
start_x= FFMAX(0, -src_x);
end_y= FFMIN(block_h, h-src_y);
end_x= FFMIN(block_w, w-src_x);
// copy existing part
for(y=start_y; y<end_y; y++){
for(x=start_x; x<end_x; x++){
buf[x + y*linesize]= src[x + y*linesize];
}
}
//top
for(y=0; y<start_y; y++){
for(x=start_x; x<end_x; x++){
buf[x + y*linesize]= buf[x + start_y*linesize];
}
}
//bottom
for(y=end_y; y<block_h; y++){
for(x=start_x; x<end_x; x++){
buf[x + y*linesize]= buf[x + (end_y-1)*linesize];
}
}
for(y=0; y<block_h; y++){
//left
for(x=0; x<start_x; x++){
buf[x + y*linesize]= buf[start_x + y*linesize];
}
//right
for(x=end_x; x<block_w; x++){
buf[x + y*linesize]= buf[end_x - 1 + y*linesize];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -