Mercurial > libavformat.hg
comparison aviobuf.c @ 418:41da3366d341 libavformat
checksuming for nut & nice checksum API for libavformat
author | michael |
---|---|
date | Mon, 05 Apr 2004 12:02:10 +0000 |
parents | e14fcd57ad2f |
children | a35263593560 |
comparison
equal
deleted
inserted
replaced
417:5a89e49ff688 | 418:41da3366d341 |
---|---|
46 s->pos = 0; | 46 s->pos = 0; |
47 s->must_flush = 0; | 47 s->must_flush = 0; |
48 s->eof_reached = 0; | 48 s->eof_reached = 0; |
49 s->is_streamed = 0; | 49 s->is_streamed = 0; |
50 s->max_packet_size = 0; | 50 s->max_packet_size = 0; |
51 s->checksum_ptr= NULL; | |
52 s->update_checksum= NULL; | |
51 return 0; | 53 return 0; |
52 } | 54 } |
53 | 55 |
54 | 56 |
55 #ifdef CONFIG_ENCODERS | 57 #ifdef CONFIG_ENCODERS |
56 static void flush_buffer(ByteIOContext *s) | 58 static void flush_buffer(ByteIOContext *s) |
57 { | 59 { |
58 if (s->buf_ptr > s->buffer) { | 60 if (s->buf_ptr > s->buffer) { |
59 if (s->write_packet) | 61 if (s->write_packet) |
60 s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer); | 62 s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer); |
63 if(s->checksum_ptr){ | |
64 s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr); | |
65 s->checksum_ptr= s->buffer; | |
66 } | |
61 s->pos += s->buf_ptr - s->buffer; | 67 s->pos += s->buf_ptr - s->buffer; |
62 } | 68 } |
63 s->buf_ptr = s->buffer; | 69 s->buf_ptr = s->buffer; |
64 } | 70 } |
65 | 71 |
241 int len; | 247 int len; |
242 | 248 |
243 /* no need to do anything if EOF already reached */ | 249 /* no need to do anything if EOF already reached */ |
244 if (s->eof_reached) | 250 if (s->eof_reached) |
245 return; | 251 return; |
252 | |
253 if(s->checksum_ptr){ | |
254 s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_end - s->checksum_ptr); | |
255 s->checksum_ptr= s->buffer; | |
256 } | |
257 | |
246 len = s->read_packet(s->opaque, s->buffer, s->buffer_size); | 258 len = s->read_packet(s->opaque, s->buffer, s->buffer_size); |
247 if (len <= 0) { | 259 if (len <= 0) { |
248 /* do not modify buffer if EOF reached so that a seek back can | 260 /* do not modify buffer if EOF reached so that a seek back can |
249 be done without rereading data */ | 261 be done without rereading data */ |
250 s->eof_reached = 1; | 262 s->eof_reached = 1; |
251 } else { | 263 } else { |
252 s->pos += len; | 264 s->pos += len; |
253 s->buf_ptr = s->buffer; | 265 s->buf_ptr = s->buffer; |
254 s->buf_end = s->buffer + len; | 266 s->buf_end = s->buffer + len; |
255 } | 267 } |
268 } | |
269 | |
270 unsigned long get_checksum(ByteIOContext *s){ | |
271 s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr); | |
272 s->checksum_ptr= NULL; | |
273 return s->checksum; | |
274 } | |
275 | |
276 void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum){ | |
277 s->update_checksum= update_checksum; | |
278 s->checksum= s->update_checksum(checksum, NULL, 0); | |
279 s->checksum_ptr= s->buf_ptr; | |
256 } | 280 } |
257 | 281 |
258 /* NOTE: return 0 if EOF, so you cannot use it if EOF handling is | 282 /* NOTE: return 0 if EOF, so you cannot use it if EOF handling is |
259 necessary */ | 283 necessary */ |
260 /* XXX: put an inline version */ | 284 /* XXX: put an inline version */ |