27
27
#include "parser.h"
30
typedef struct PNGParseContext
30
typedef struct PNGParseContext {
34
uint32_t chunk_length;
35
uint32_t remaining_size;
32
uint32_t chunk_pos; ///< position inside current chunk
33
uint32_t chunk_length; ///< length of the current chunk
34
uint32_t remaining_size; ///< remaining size of the current chunk
38
37
static int png_parse(AVCodecParserContext *s, AVCodecContext *avctx,
62
61
ppc->pc.state64 = state64;
64
if (ppc->remaining_size) {
65
i = FFMIN(ppc->remaining_size, buf_size);
66
ppc->remaining_size -= i;
67
if (ppc->remaining_size)
69
if (ppc->index == -1) {
62
} else if (ppc->remaining_size) {
63
i = FFMIN(ppc->remaining_size, buf_size);
64
ppc->remaining_size -= i;
65
if (ppc->remaining_size)
67
if (ppc->chunk_pos == -1) {
75
for (;ppc->pc.frame_start_found && i < buf_size; i++) {
76
ppc->pc.state = (ppc->pc.state<<8) | buf[i];
77
if (ppc->index == 3) {
73
for (; ppc->pc.frame_start_found && i < buf_size; i++) {
74
ppc->pc.state = (ppc->pc.state << 8) | buf[i];
75
if (ppc->chunk_pos == 3) {
78
76
ppc->chunk_length = ppc->pc.state;
79
77
if (ppc->chunk_length > 0x7fffffff) {
80
ppc->index = ppc->pc.frame_start_found = 0;
78
ppc->chunk_pos = ppc->pc.frame_start_found = 0;
83
81
ppc->chunk_length += 4;
84
} else if (ppc->index == 7) {
82
} else if (ppc->chunk_pos == 7) {
85
83
if (ppc->chunk_length >= buf_size - i)
86
ppc->remaining_size = ppc->chunk_length - buf_size + i + 1;
84
ppc->remaining_size = ppc->chunk_length - buf_size + i + 1;
87
85
if (ppc->pc.state == MKBETAG('I', 'E', 'N', 'D')) {
88
86
if (ppc->remaining_size)
91
89
next = ppc->chunk_length + i + 1;
95
93
if (ppc->remaining_size)
105
104
if (ff_combine_frame(&ppc->pc, next, &buf, &buf_size) < 0)
108
ppc->index = ppc->pc.frame_start_found = 0;
107
ppc->chunk_pos = ppc->pc.frame_start_found = 0;
111
110
*poutbuf_size = buf_size;