Commit 26b4fe82 authored by Aurelien Jacobs's avatar Aurelien Jacobs

split h264.c to move parser in its own file

Originally committed as revision 8985 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent eca3810e
...@@ -679,6 +679,7 @@ flashsv_encoder_deps="zlib" ...@@ -679,6 +679,7 @@ flashsv_encoder_deps="zlib"
flv_decoder_deps="h263_decoder" flv_decoder_deps="h263_decoder"
h263_decoder_deps="h263_parser mpeg4video_parser" h263_decoder_deps="h263_parser mpeg4video_parser"
h263i_decoder_deps="h263_decoder" h263i_decoder_deps="h263_decoder"
h264_decoder_deps="h264_parser"
mpeg_xvmc_decoder_deps="xvmc" mpeg_xvmc_decoder_deps="xvmc"
mpeg4_decoder_deps="h263_decoder" mpeg4_decoder_deps="h263_decoder"
msmpeg4v1_decoder_deps="h263_decoder" msmpeg4v1_decoder_deps="h263_decoder"
......
...@@ -290,7 +290,7 @@ OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o ...@@ -290,7 +290,7 @@ OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o
OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o
OBJS-$(CONFIG_H261_PARSER) += h261_parser.o OBJS-$(CONFIG_H261_PARSER) += h261_parser.o
OBJS-$(CONFIG_H263_PARSER) += h263_parser.o OBJS-$(CONFIG_H263_PARSER) += h263_parser.o
OBJS-$(CONFIG_H264_PARSER) += h264.o OBJS-$(CONFIG_H264_PARSER) += h264_parser.o
OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg.o OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg.o
OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o
OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
* Context Adaptive Binary Arithmetic Coder. * Context Adaptive Binary Arithmetic Coder.
*/ */
#ifndef CABAC_H
#define CABAC_H
#include "bitstream.h"
//#undef NDEBUG //#undef NDEBUG
#include <assert.h> #include <assert.h>
...@@ -857,3 +861,5 @@ static int get_cabac_ueg(CABACContext *c, uint8_t * state, int max, int is_signe ...@@ -857,3 +861,5 @@ static int get_cabac_ueg(CABACContext *c, uint8_t * state, int max, int is_signe
}else }else
return i; return i;
} }
#endif /* CABAC_H */
This diff is collapsed.
This diff is collapsed.
/*
* H.26L/H.264/AVC/JVT/14496-10/... parser
* 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_parser.c
* H.264 / AVC / MPEG4 part10 parser.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "parser.h"
#include "h264_parser.h"
#include <assert.h>
int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size)
{
int i;
uint32_t state;
ParseContext *pc = &(h->s.parse_context);
//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]);
// mb_addr= pc->mb_addr - 1;
state= pc->state;
if(state>13)
state= 7;
for(i=0; i<buf_size; i++){
if(state==7){
for(; i<buf_size; i++){
if(!buf[i]){
state=2;
break;
}
}
}else if(state<=2){
if(buf[i]==1) state^= 5; //2->7, 1->4, 0->5
else if(buf[i]) state = 7;
else state>>=1; //2->1, 1->0, 0->0
}else if(state<=5){
int v= buf[i] & 0x1F;
if(v==7 || v==8 || v==9){
if(pc->frame_start_found){
i++;
found:
pc->state=7;
pc->frame_start_found= 0;
return i-(state&5);
}
}else if(v==1 || v==2 || v==5){
if(pc->frame_start_found){
state+=8;
continue;
}else
pc->frame_start_found = 1;
}
state= 7;
}else{
if(buf[i] & 0x80)
goto found;
state= 7;
}
}
pc->state= state;
return END_NOT_FOUND;
}
static int h264_parse(AVCodecParserContext *s,
AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size)
{
H264Context *h = s->priv_data;
ParseContext *pc = &h->s.parse_context;
int next;
if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
next= buf_size;
}else{
next= ff_h264_find_frame_end(h, buf, buf_size);
if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
*poutbuf = NULL;
*poutbuf_size = 0;
return buf_size;
}
if(next<0 && next != END_NOT_FOUND){
assert(pc->last_index + next >= 0 );
ff_h264_find_frame_end(h, &pc->buffer[pc->last_index + next], -next); //update state
}
}
*poutbuf = buf;
*poutbuf_size = buf_size;
return next;
}
static int h264_split(AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
int i;
uint32_t state = -1;
int has_sps= 0;
for(i=0; i<=buf_size; i++){
if((state&0xFFFFFF1F) == 0x107)
has_sps=1;
/* if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){
}*/
if((state&0xFFFFFF00) == 0x100 && (state&0xFFFFFF1F) != 0x107 && (state&0xFFFFFF1F) != 0x108 && (state&0xFFFFFF1F) != 0x109){
if(has_sps){
while(i>4 && buf[i-5]==0) i--;
return i-4;
}
}
if (i<buf_size)
state= (state<<8) | buf[i];
}
return 0;
}
AVCodecParser h264_parser = {
{ CODEC_ID_H264 },
sizeof(H264Context),
NULL,
h264_parse,
ff_parse_close,
h264_split,
};
/*
* H.26L/H.264/AVC/JVT/14496-10/... parser
* 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_parser.h
* H.264 / AVC / MPEG4 part10 parser.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#ifndef H264_PARSER_H
#define H264_PARSER_H
#include "h264.h"
/**
* finds the end of the current frame in the bitstream.
* @return the position of the first byte of the next frame, or -1
*/
int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size);
#endif /* H264_PARSER_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment