Statistics
| Branch: | Revision:

ffmpeg / libavcodec / vc1_parser.c @ bbb7d4c7

History | View | Annotate | Download (3.24 KB)

1
/*
2
 * VC-1 and WMV3 parser
3
 * Copyright (c) 2006-2007 Konstantin Shishkov
4
 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

    
23
/**
24
 * @file vc1_parser.c
25
 * VC-1 and WMV3 parser
26
 */
27

    
28
#include "parser.h"
29
#define VC1_PARSER_ONLY
30
#include "vc1.h"
31

    
32
/**
33
 * finds the end of the current frame in the bitstream.
34
 * @return the position of the first byte of the next frame, or -1
35
 */
36
static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf,
37
                               int buf_size) {
38
    int pic_found, i;
39
    uint32_t state;
40

    
41
    pic_found= pc->frame_start_found;
42
    state= pc->state;
43

    
44
    i=0;
45
    if(!pic_found){
46
        for(i=0; i<buf_size; i++){
47
            state= (state<<8) | buf[i];
48
            if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){
49
                i++;
50
                pic_found=1;
51
                break;
52
            }
53
        }
54
    }
55

    
56
    if(pic_found){
57
        /* EOF considered as end of frame */
58
        if (buf_size == 0)
59
            return 0;
60
        for(; i<buf_size; i++){
61
            state= (state<<8) | buf[i];
62
            if(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){
63
                pc->frame_start_found=0;
64
                pc->state=-1;
65
                return i-3;
66
            }
67
        }
68
    }
69
    pc->frame_start_found= pic_found;
70
    pc->state= state;
71
    return END_NOT_FOUND;
72
}
73

    
74
static int vc1_parse(AVCodecParserContext *s,
75
                           AVCodecContext *avctx,
76
                           uint8_t **poutbuf, int *poutbuf_size,
77
                           const uint8_t *buf, int buf_size)
78
{
79
    ParseContext *pc = s->priv_data;
80
    int next;
81

    
82
    if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
83
        next= buf_size;
84
    }else{
85
        next= vc1_find_frame_end(pc, buf, buf_size);
86

    
87
        if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
88
            *poutbuf = NULL;
89
            *poutbuf_size = 0;
90
            return buf_size;
91
        }
92
    }
93
    *poutbuf = (uint8_t *)buf;
94
    *poutbuf_size = buf_size;
95
    return next;
96
}
97

    
98
static int vc1_split(AVCodecContext *avctx,
99
                           const uint8_t *buf, int buf_size)
100
{
101
    int i;
102
    uint32_t state= -1;
103

    
104
    for(i=0; i<buf_size; i++){
105
        state= (state<<8) | buf[i];
106
        if(IS_MARKER(state) && state != VC1_CODE_SEQHDR && state != VC1_CODE_ENTRYPOINT)
107
            return i-3;
108
    }
109
    return 0;
110
}
111

    
112
AVCodecParser vc1_parser = {
113
    { CODEC_ID_VC1 },
114
    sizeof(ParseContext1),
115
    NULL,
116
    vc1_parse,
117
    ff_parse1_close,
118
    vc1_split,
119
};