diff options
author | XhmikosR <xhmikosr@users.sourceforge.net> | 2010-04-09 18:12:59 +0400 |
---|---|---|
committer | XhmikosR <xhmikosr@users.sourceforge.net> | 2010-04-09 18:12:59 +0400 |
commit | efbc9d9043ff8ff92716ddd00a5f61412d535593 (patch) | |
tree | 8f3e621f756cf1f5b4d64d97964c7e7abd8aaf08 /src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/parser.c | |
parent | df6b139a6d9027156f614b68687e039e3a5854db (diff) |
revert r1783
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1785 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/parser.c')
-rw-r--r-- | src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/parser.c | 187 |
1 files changed, 80 insertions, 107 deletions
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/parser.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/parser.c index 5789d959f..3b5097950 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/parser.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/parser.c @@ -24,8 +24,7 @@ static AVCodecParser *av_first_parser = NULL;
-AVCodecParser* av_parser_next(AVCodecParser *p)
-{
+AVCodecParser* av_parser_next(AVCodecParser *p){
if(p) return p->next;
else return av_first_parser;
}
@@ -45,38 +44,34 @@ AVCodecParserContext *av_parser_init(int codec_id) if(codec_id == CODEC_ID_NONE)
return NULL;
- for(parser = av_first_parser; parser != NULL; parser = parser->next)
- {
- if(parser->codec_ids[0] == codec_id ||
- parser->codec_ids[1] == codec_id ||
- parser->codec_ids[2] == codec_id ||
- parser->codec_ids[3] == codec_id ||
- parser->codec_ids[4] == codec_id)
+ for(parser = av_first_parser; parser != NULL; parser = parser->next) {
+ if (parser->codec_ids[0] == codec_id ||
+ parser->codec_ids[1] == codec_id ||
+ parser->codec_ids[2] == codec_id ||
+ parser->codec_ids[3] == codec_id ||
+ parser->codec_ids[4] == codec_id)
goto found;
}
return NULL;
-found:
+ found:
s = av_mallocz(sizeof(AVCodecParserContext));
- if(!s)
+ if (!s)
return NULL;
s->parser = parser;
s->priv_data = av_mallocz(parser->priv_data_size);
- if(!s->priv_data)
- {
+ if (!s->priv_data) {
av_free(s);
return NULL;
}
- if(parser->parser_init)
- {
+ if (parser->parser_init) {
ret = parser->parser_init(s);
- if(ret != 0)
- {
+ if (ret != 0) {
av_free(s->priv_data);
av_free(s);
return NULL;
}
}
- s->fetch_timestamp = 1;
+ s->fetch_timestamp=1;
s->pict_type = FF_I_TYPE;
s->key_frame = -1;
s->convergence_duration = AV_NOPTS_VALUE;
@@ -86,27 +81,24 @@ found: return s;
}
-void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove)
-{
+void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove){
int i;
- s->dts = s->pts = AV_NOPTS_VALUE;
- s->pos = -1;
- s->offset = 0;
- for(i = 0; i < AV_PARSER_PTS_NB; i++)
- {
- if(s->cur_offset + off >= s->cur_frame_offset[i]
- && (s->frame_offset < s->cur_frame_offset[i] ||
- (!s->frame_offset && !s->next_frame_offset)) // first field/frame
- //check is disabled becausue mpeg-ts doesnt send complete PES packets
- && /*s->next_frame_offset + off <*/ s->cur_frame_end[i])
- {
- s->dts = s->cur_frame_dts[i];
- s->pts = s->cur_frame_pts[i];
- s->pos = s->cur_frame_pos[i];
+ s->dts= s->pts= AV_NOPTS_VALUE;
+ s->pos= -1;
+ s->offset= 0;
+ for(i = 0; i < AV_PARSER_PTS_NB; i++) {
+ if ( s->cur_offset + off >= s->cur_frame_offset[i]
+ && (s->frame_offset < s->cur_frame_offset[i] ||
+ (!s->frame_offset && !s->next_frame_offset)) // first field/frame
+ //check is disabled becausue mpeg-ts doesnt send complete PES packets
+ && /*s->next_frame_offset + off <*/ s->cur_frame_end[i]){
+ s->dts= s->cur_frame_dts[i];
+ s->pts= s->cur_frame_pts[i];
+ s->pos= s->cur_frame_pos[i];
s->offset = s->next_frame_offset - s->cur_frame_offset[i];
if(remove)
- s->cur_frame_offset[i] = INT64_MAX;
+ s->cur_frame_offset[i]= INT64_MAX;
if(s->cur_offset + off < s->cur_frame_end[i])
break;
}
@@ -158,28 +150,24 @@ int av_parser_parse2(AVCodecParserContext *s, int index, i;
uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE];
- if(buf_size == 0)
- {
+ if (buf_size == 0) {
/* padding is always necessary even if EOF, so we add it here */
memset(dummy_buf, 0, sizeof(dummy_buf));
buf = dummy_buf;
- }
- else if(s->cur_offset + buf_size !=
- s->cur_frame_end[s->cur_frame_start_index]) /* skip remainder packets */
- {
+ } else if (s->cur_offset + buf_size !=
+ s->cur_frame_end[s->cur_frame_start_index]) { /* skip remainder packets */
/* add a new packet descriptor */
- i = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1);
- s->cur_frame_start_index = i;
- s->cur_frame_offset[i] = s->cur_offset;
- s->cur_frame_end[i] = s->cur_offset + buf_size;
- s->cur_frame_pts[i] = pts;
- s->cur_frame_dts[i] = dts;
- s->cur_frame_pos[i] = pos;
+ i = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1);
+ s->cur_frame_start_index = i;
+ s->cur_frame_offset[i] = s->cur_offset;
+ s->cur_frame_end[i] = s->cur_offset + buf_size;
+ s->cur_frame_pts[i] = pts;
+ s->cur_frame_dts[i] = dts;
+ s->cur_frame_pos[i] = pos;
}
- if(s->fetch_timestamp)
- {
- s->fetch_timestamp = 0;
+ if (s->fetch_timestamp){
+ s->fetch_timestamp=0;
s->last_pts = s->pts;
s->last_dts = s->dts;
s->last_pos = s->pos;
@@ -190,16 +178,15 @@ int av_parser_parse2(AVCodecParserContext *s, index = s->parser->parser_parse(s, avctx, (const uint8_t **)poutbuf, poutbuf_size, buf, buf_size);
//av_log(NULL, AV_LOG_DEBUG, "parser: in:%"PRId64", %"PRId64", out:%"PRId64", %"PRId64", in:%d out:%d id:%d\n", pts, dts, s->last_pts, s->last_dts, buf_size, *poutbuf_size, avctx->codec_id);
/* update the file pointer */
- if(*poutbuf_size)
- {
+ if (*poutbuf_size) {
/* fill the data for the current frame */
s->frame_offset = s->next_frame_offset;
/* offset of the next frame */
s->next_frame_offset = s->cur_offset + index;
- s->fetch_timestamp = 1;
+ s->fetch_timestamp=1;
}
- if(index < 0)
+ if (index < 0)
index = 0;
s->cur_offset += index;
return index;
@@ -213,31 +200,26 @@ int av_parser_parse2(AVCodecParserContext *s, int av_parser_change(AVCodecParserContext *s,
AVCodecContext *avctx,
uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size, int keyframe)
-{
+ const uint8_t *buf, int buf_size, int keyframe){
- if(s && s->parser->split)
- {
- if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))
- {
- int i = s->parser->split(avctx, buf, buf_size);
+ if(s && s->parser->split){
+ if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){
+ int i= s->parser->split(avctx, buf, buf_size);
buf += i;
buf_size -= i;
}
}
/* cast to avoid warning about discarding qualifiers */
- *poutbuf = (uint8_t *) buf;
- *poutbuf_size = buf_size;
- if(avctx->extradata)
- {
- if((keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))
- /*||(s->pict_type != FF_I_TYPE && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/
- /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/)
- {
- int size = buf_size + avctx->extradata_size;
- *poutbuf_size = size;
- *poutbuf = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+ *poutbuf= (uint8_t *) buf;
+ *poutbuf_size= buf_size;
+ if(avctx->extradata){
+ if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))
+ /*||(s->pict_type != FF_I_TYPE && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/
+ /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
+ int size= buf_size + avctx->extradata_size;
+ *poutbuf_size= size;
+ *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);
memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
@@ -250,9 +232,8 @@ int av_parser_change(AVCodecParserContext *s, void av_parser_close(AVCodecParserContext *s)
{
- if(s)
- {
- if(s->parser->parser_close)
+ if(s){
+ if (s->parser->parser_close)
s->parser->parser_close(s);
av_free(s->priv_data);
av_free(s);
@@ -268,30 +249,26 @@ void av_parser_close(AVCodecParserContext *s) int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
{
#if 0
- if(pc->overread)
- {
+ if(pc->overread){
printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
- printf("%X %X %X %X\n", (*buf)[0], (*buf)[1], (*buf)[2], (*buf)[3]);
+ printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
}
#endif
/* Copy overread bytes from last frame into buffer. */
- for(; pc->overread > 0; pc->overread--)
- {
- pc->buffer[pc->index++] = pc->buffer[pc->overread_index++];
+ for(; pc->overread>0; pc->overread--){
+ pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
}
/* flush remaining if EOF */
- if(!*buf_size && next == END_NOT_FOUND)
- {
- next = 0;
+ if(!*buf_size && next == END_NOT_FOUND){
+ next= 0;
}
- pc->last_index = pc->index;
+ pc->last_index= pc->index;
/* copy into buffer end return */
- if(next == END_NOT_FOUND)
- {
+ if(next == END_NOT_FOUND){
void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
if(!new_buffer)
@@ -302,35 +279,32 @@ int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_s return -1;
}
- *buf_size =
- pc->overread_index = pc->index + next;
+ *buf_size=
+ pc->overread_index= pc->index + next;
/* append to buffer */
- if(pc->index)
- {
+ if(pc->index){
void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
if(!new_buffer)
return AVERROR(ENOMEM);
pc->buffer = new_buffer;
- memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE);
+ memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
pc->index = 0;
- *buf = pc->buffer;
+ *buf= pc->buffer;
}
/* store overread bytes */
- for(; next < 0; next++)
- {
- pc->state = (pc->state << 8) | pc->buffer[pc->last_index + next];
- pc->state64 = (pc->state64 << 8) | pc->buffer[pc->last_index + next];
+ for(;next < 0; next++){
+ pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next];
+ pc->state64 = (pc->state64<<8) | pc->buffer[pc->last_index + next];
pc->overread++;
}
#if 0
- if(pc->overread)
- {
+ if(pc->overread){
printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
- printf("%X %X %X %X\n", (*buf)[0], (*buf)[1], (*buf)[2], (*buf)[3]);
+ printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
}
#endif
@@ -355,16 +329,15 @@ void ff_parse1_close(AVCodecParserContext *s) /*************************/
int ff_mpeg4video_split(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
+ const uint8_t *buf, int buf_size)
{
int i;
- uint32_t state = -1;
+ uint32_t state= -1;
- for(i = 0; i < buf_size; i++)
- {
- state = (state << 8) | buf[i];
+ for(i=0; i<buf_size; i++){
+ state= (state<<8) | buf[i];
if(state == 0x1B3 || state == 0x1B6)
- return i - 3;
+ return i-3;
}
return 0;
}
|