diff --git a/src/drivers/Qt/avi/avi-utils.cpp b/src/drivers/Qt/avi/avi-utils.cpp index 64f76c93..e009f76c 100644 --- a/src/drivers/Qt/avi/avi-utils.cpp +++ b/src/drivers/Qt/avi/avi-utils.cpp @@ -41,64 +41,68 @@ #include "Qt/avi/gwavi.h" int -gwavi_t::write_avi_header(FILE *out, struct gwavi_header_t *avi_header) +gwavi_t::write_avi_header(FILE *fp, struct gwavi_header_t *avi_header) { long marker, t; - if (write_chars_bin(out, "avih", 4) == -1) { + if (write_chars_bin(fp, "avih", 4) == -1) { (void)fprintf(stderr, "write_avi_header: write_chars_bin() " "failed\n"); return -1; } - if ((marker = ftell(out)) == -1) { + if ((marker = ftell(fp)) == -1) { perror("write_avi_header (ftell)"); return -1; } - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if (write_int(out, avi_header->time_delay) == -1) + if (write_int(fp, avi_header->time_delay) == -1) goto write_int_failed; - if (write_int(out, avi_header->data_rate) == -1) + if (write_int(fp, avi_header->data_rate) == -1) goto write_int_failed; - if (write_int(out, avi_header->reserved) == -1) + if (write_int(fp, avi_header->reserved) == -1) goto write_int_failed; /* dwFlags */ - if (write_int(out, avi_header->flags) == -1) + if (write_int(fp, avi_header->flags) == -1) goto write_int_failed; /* dwTotalFrames */ - if (write_int(out, avi_header->number_of_frames) == -1) + if (write_int(fp, avi_header->number_of_frames) == -1) goto write_int_failed; - if (write_int(out, avi_header->initial_frames) == -1) + if (write_int(fp, avi_header->initial_frames) == -1) goto write_int_failed; - if (write_int(out, avi_header->data_streams) == -1) + if (write_int(fp, avi_header->data_streams) == -1) goto write_int_failed; - if (write_int(out, avi_header->buffer_size) == -1) + if (write_int(fp, avi_header->buffer_size) == -1) goto write_int_failed; - if (write_int(out, avi_header->width) == -1) + if (write_int(fp, avi_header->width) == -1) goto write_int_failed; - if (write_int(out, avi_header->height) == -1) + if (write_int(fp, avi_header->height) == -1) goto write_int_failed; - if (write_int(out, avi_header->time_scale) == -1) + if (write_int(fp, avi_header->time_scale) == -1) goto write_int_failed; - if (write_int(out, avi_header->playback_data_rate) == -1) + if (write_int(fp, avi_header->playback_data_rate) == -1) goto write_int_failed; - if (write_int(out, avi_header->starting_time) == -1) + if (write_int(fp, avi_header->starting_time) == -1) goto write_int_failed; - if (write_int(out, avi_header->data_length) == -1) + if (write_int(fp, avi_header->data_length) == -1) goto write_int_failed; - if ((t = ftell(out)) == -1) { + if ((t = ftell(fp)) == -1) { perror("write_avi_header (ftell)"); return -1; } - if (fseek(out, marker, SEEK_SET) == -1) { + if (fseek(fp, marker, SEEK_SET) == -1) { perror("write_avi_header (fseek)"); return -1; } - if (write_int(out, (unsigned int)(t - marker - 4)) == -1) + if (write_int(fp, (unsigned int)(t - marker - 4)) == -1) + { goto write_int_failed; - if (fseek(out, t, SEEK_SET) == -1) { + } + + if (fseek(fp, t, SEEK_SET) == -1) + { perror("write_avi_header (fseek)"); return -1; } @@ -111,58 +115,60 @@ write_int_failed: } int -gwavi_t::write_stream_header(FILE *out, struct gwavi_stream_header_t *stream_header) +gwavi_t::write_stream_header(FILE *fp, struct gwavi_stream_header_t *stream_header) { long marker, t; - if (write_chars_bin(out, "strh", 4) == -1) + if (write_chars_bin(fp, "strh", 4) == -1) goto write_chars_bin_failed; - if ((marker = ftell(out)) == -1) { + if ((marker = ftell(fp)) == -1) { perror("write_stream_header (ftell)"); return -1; } - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if (write_chars_bin(out, stream_header->data_type, 4) == -1) + if (write_chars_bin(fp, stream_header->data_type, 4) == -1) goto write_chars_bin_failed; - if (write_chars_bin(out, stream_header->codec, 4) == -1) + if (write_chars_bin(fp, stream_header->codec, 4) == -1) goto write_chars_bin_failed; - if (write_int(out, stream_header->flags) == -1) + if (write_int(fp, stream_header->flags) == -1) goto write_int_failed; - if (write_int(out, stream_header->priority) == -1) + if (write_int(fp, stream_header->priority) == -1) goto write_int_failed; - if (write_int(out, stream_header->initial_frames) == -1) + if (write_int(fp, stream_header->initial_frames) == -1) goto write_int_failed; - if (write_int(out, stream_header->time_scale) == -1) + if (write_int(fp, stream_header->time_scale) == -1) goto write_int_failed; - if (write_int(out, stream_header->data_rate) == -1) + if (write_int(fp, stream_header->data_rate) == -1) goto write_int_failed; - if (write_int(out, stream_header->start_time) == -1) + if (write_int(fp, stream_header->start_time) == -1) goto write_int_failed; - if (write_int(out, stream_header->data_length) == -1) + if (write_int(fp, stream_header->data_length) == -1) goto write_int_failed; - if (write_int(out, stream_header->buffer_size) == -1) + if (write_int(fp, stream_header->buffer_size) == -1) goto write_int_failed; - if (write_int(out, stream_header->video_quality) == -1) + if (write_int(fp, stream_header->video_quality) == -1) goto write_int_failed; - if (write_int(out, stream_header->sample_size) == -1) + if (write_int(fp, stream_header->sample_size) == -1) goto write_int_failed; - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if ((t = ftell(out)) == -1) { + if ((t = ftell(fp)) == -1) { perror("write_stream_header (ftell)"); return -1; } - if (fseek(out, marker, SEEK_SET) == -1) { + if (fseek(fp, marker, SEEK_SET) == -1) { perror("write_stream_header (fseek)"); return -1; } - write_int(out, (unsigned int)(t - marker - 4)); - if (fseek(out, t, SEEK_SET) == -1){ + write_int(fp, (unsigned int)(t - marker - 4)); + + if (fseek(fp, t, SEEK_SET) == -1) + { perror("write_stream_header (fseek)"); return -1; } @@ -179,78 +185,78 @@ write_chars_bin_failed: } int -gwavi_t::write_stream_format_v(FILE *out, struct gwavi_stream_format_v_t *stream_format_v) +gwavi_t::write_stream_format_v(FILE *fp, struct gwavi_stream_format_v_t *stream_format_v) { long marker,t; unsigned int i; - if (write_chars_bin(out, "strf", 4) == -1) { + if (write_chars_bin(fp, "strf", 4) == -1) { (void)fprintf(stderr, "write_stream_format_v: write_chars_bin()" " failed\n"); return -1; } - if ((marker = ftell(out)) == -1) { + if ((marker = ftell(fp)) == -1) { perror("write_stream_format_v (ftell)"); return -1; } - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if (write_int(out, stream_format_v->header_size) == -1) + if (write_int(fp, stream_format_v->header_size) == -1) goto write_int_failed; - if (write_int(out, stream_format_v->width) == -1) + if (write_int(fp, stream_format_v->width) == -1) goto write_int_failed; - if (write_int(out, stream_format_v->height) == -1) + if (write_int(fp, stream_format_v->height) == -1) goto write_int_failed; - if (write_short(out, stream_format_v->num_planes) == -1) { + if (write_short(fp, stream_format_v->num_planes) == -1) { (void)fprintf(stderr, "write_stream_format_v: write_short() " "failed\n"); return -1; } - if (write_short(out, stream_format_v->bits_per_pixel) == -1) { + if (write_short(fp, stream_format_v->bits_per_pixel) == -1) { (void)fprintf(stderr, "write_stream_format_v: write_short() " "failed\n"); return -1; } - if (write_int(out, stream_format_v->compression_type) == -1) + if (write_int(fp, stream_format_v->compression_type) == -1) goto write_int_failed; - if (write_int(out, stream_format_v->image_size) == -1) + if (write_int(fp, stream_format_v->image_size) == -1) goto write_int_failed; - if (write_int(out, stream_format_v->x_pels_per_meter) == -1) + if (write_int(fp, stream_format_v->x_pels_per_meter) == -1) goto write_int_failed; - if (write_int(out, stream_format_v->y_pels_per_meter) == -1) + if (write_int(fp, stream_format_v->y_pels_per_meter) == -1) goto write_int_failed; - if (write_int(out, stream_format_v->colors_used) == -1) + if (write_int(fp, stream_format_v->colors_used) == -1) goto write_int_failed; - if (write_int(out, stream_format_v->colors_important) == -1) + if (write_int(fp, stream_format_v->colors_important) == -1) goto write_int_failed; if (stream_format_v->colors_used != 0) for (i = 0; i < stream_format_v->colors_used; i++) { - if (fputc(stream_format_v->palette[i] & 255, out) + if (fputc(stream_format_v->palette[i] & 255, fp) == EOF) goto fputc_failed; - if (fputc((stream_format_v->palette[i] >> 8) & 255, out) + if (fputc((stream_format_v->palette[i] >> 8) & 255, fp) == EOF) goto fputc_failed; - if (fputc((stream_format_v->palette[i] >> 16) & 255, out) + if (fputc((stream_format_v->palette[i] >> 16) & 255, fp) == EOF) goto fputc_failed; - if (fputc(0, out) == EOF) + if (fputc(0, fp) == EOF) goto fputc_failed; } - if ((t = ftell(out)) == -1) { + if ((t = ftell(fp)) == -1) { perror("write_stream_format_v (ftell)"); return -1; } - if (fseek(out,marker,SEEK_SET) == -1) { + if (fseek(fp,marker,SEEK_SET) == -1) { perror("write_stream_format_v (fseek)"); return -1; } - if (write_int(out, (unsigned int)(t - marker - 4)) == -1) + if (write_int(fp, (unsigned int)(t - marker - 4)) == -1) goto write_int_failed; - if (fseek(out, t, SEEK_SET) == -1) { + if (fseek(fp, t, SEEK_SET) == -1) { perror("write_stream_format_v (fseek)"); return -1; } @@ -267,48 +273,48 @@ fputc_failed: } int -gwavi_t::write_stream_format_a(FILE *out, struct gwavi_stream_format_a_t *stream_format_a) +gwavi_t::write_stream_format_a(FILE *fp, struct gwavi_stream_format_a_t *stream_format_a) { long marker, t; - if (write_chars_bin(out, "strf", 4) == -1) { + if (write_chars_bin(fp, "strf", 4) == -1) { (void)fprintf(stderr, "write_stream_format_a: write_chars_bin()" " failed\n"); return -1; } - if ((marker = ftell(out)) == -1) { + if ((marker = ftell(fp)) == -1) { perror("write_stream_format_a (ftell)"); return -1; } - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if (write_short(out, stream_format_a->format_type) == -1) + if (write_short(fp, stream_format_a->format_type) == -1) goto write_short_failed; - if (write_short(out, stream_format_a->channels) == -1) + if (write_short(fp, stream_format_a->channels) == -1) goto write_short_failed; - if (write_int(out, stream_format_a->sample_rate) == -1) + if (write_int(fp, stream_format_a->sample_rate) == -1) goto write_int_failed; - if (write_int(out, stream_format_a->bytes_per_second) == -1) + if (write_int(fp, stream_format_a->bytes_per_second) == -1) goto write_int_failed; - if (write_short(out, stream_format_a->block_align) == -1) + if (write_short(fp, stream_format_a->block_align) == -1) goto write_short_failed; - if (write_short(out, stream_format_a->bits_per_sample) == -1) + if (write_short(fp, stream_format_a->bits_per_sample) == -1) goto write_short_failed; - if (write_short(out, stream_format_a->size) == -1) + if (write_short(fp, stream_format_a->size) == -1) goto write_short_failed; - if ((t = ftell(out)) == -1) { + if ((t = ftell(fp)) == -1) { perror("write_stream_format_a (ftell)"); return -1; } - if (fseek(out, marker, SEEK_SET) == -1) { + if (fseek(fp, marker, SEEK_SET) == -1) { perror("write_stream_format_a (fseek)"); return -1; } - if (write_int(out, (unsigned int)(t - marker - 4)) == -1) + if (write_int(fp, (unsigned int)(t - marker - 4)) == -1) goto write_int_failed; - if (fseek(out, t, SEEK_SET) == -1) { + if (fseek(fp, t, SEEK_SET) == -1) { perror("write_stream_format_a (fseek)"); return -1; } @@ -325,91 +331,91 @@ write_short_failed: } int -gwavi_t::write_avi_header_chunk(void) +gwavi_t::write_avi_header_chunk(FILE *fp) { long marker, t; long sub_marker; - if (write_chars_bin(out, "LIST", 4) == -1) + if (write_chars_bin(fp, "LIST", 4) == -1) goto write_chars_bin_failed; - if ((marker = ftell(out)) == -1) + if ((marker = ftell(fp)) == -1) goto ftell_failed; - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if (write_chars_bin(out, "hdrl", 4) == -1) + if (write_chars_bin(fp, "hdrl", 4) == -1) goto write_chars_bin_failed; - if (write_avi_header(out, &avi_header) == -1) { + if (write_avi_header(fp, &avi_header) == -1) { (void)fprintf(stderr, "write_avi_header_chunk: " "write_avi_header() failed\n"); return -1; } - if (write_chars_bin(out, "LIST", 4) == -1) + if (write_chars_bin(fp, "LIST", 4) == -1) goto write_chars_bin_failed; - if ((sub_marker = ftell(out)) == -1) + if ((sub_marker = ftell(fp)) == -1) goto ftell_failed; - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if (write_chars_bin(out, "strl", 4) == -1) + if (write_chars_bin(fp, "strl", 4) == -1) goto write_chars_bin_failed; - if (write_stream_header(out, &stream_header_v) == -1) { + if (write_stream_header(fp, &stream_header_v) == -1) { (void)fprintf(stderr, "write_avi_header_chunk: " "write_stream_header failed\n"); return -1; } - if (write_stream_format_v(out, &stream_format_v) == -1) { + if (write_stream_format_v(fp, &stream_format_v) == -1) { (void)fprintf(stderr, "write_avi_header_chunk: " "write_stream_format_v failed\n"); return -1; } - if ((t = ftell(out)) == -1) + if ((t = ftell(fp)) == -1) goto ftell_failed; - if (fseek(out, sub_marker, SEEK_SET) == -1) + if (fseek(fp, sub_marker, SEEK_SET) == -1) goto fseek_failed; - if (write_int(out, (unsigned int)(t - sub_marker - 4)) == -1) + if (write_int(fp, (unsigned int)(t - sub_marker - 4)) == -1) goto write_int_failed; - if (fseek(out, t, SEEK_SET) == -1) + if (fseek(fp, t, SEEK_SET) == -1) goto fseek_failed; if (avi_header.data_streams == 2) { - if (write_chars_bin(out, "LIST", 4) == -1) + if (write_chars_bin(fp, "LIST", 4) == -1) goto write_chars_bin_failed; - if ((sub_marker = ftell(out)) == -1) + if ((sub_marker = ftell(fp)) == -1) goto ftell_failed; - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - if (write_chars_bin(out, "strl", 4) == -1) + if (write_chars_bin(fp, "strl", 4) == -1) goto write_chars_bin_failed; - if (write_stream_header(out, &stream_header_a) == -1) { + if (write_stream_header(fp, &stream_header_a) == -1) { (void)fprintf(stderr, "write_avi_header_chunk: " "write_stream_header failed\n"); return -1; } - if (write_stream_format_a(out, &stream_format_a) == -1) { + if (write_stream_format_a(fp, &stream_format_a) == -1) { (void)fprintf(stderr, "write_avi_header_chunk: " "write_stream_format_a failed\n"); return -1; } - if ((t = ftell(out)) == -1) + if ((t = ftell(fp)) == -1) goto ftell_failed; - if (fseek(out, sub_marker, SEEK_SET) == -1) + if (fseek(fp, sub_marker, SEEK_SET) == -1) goto fseek_failed; - if (write_int(out, (unsigned int)(t - sub_marker - 4)) == -1) + if (write_int(fp, (unsigned int)(t - sub_marker - 4)) == -1) goto write_int_failed; - if (fseek(out, t, SEEK_SET) == -1) + if (fseek(fp, t, SEEK_SET) == -1) goto fseek_failed; } - if ((t = ftell(out)) == -1) + if ((t = ftell(fp)) == -1) goto ftell_failed; - if (fseek(out, marker, SEEK_SET) == -1) + if (fseek(fp, marker, SEEK_SET) == -1) goto fseek_failed; - if (write_int(out, (unsigned int)(t - marker - 4)) == -1) + if (write_int(fp, (unsigned int)(t - marker - 4)) == -1) goto write_int_failed; - if (fseek(out, t, SEEK_SET) == -1) + if (fseek(fp, t, SEEK_SET) == -1) goto fseek_failed; return 0; @@ -431,39 +437,69 @@ write_chars_bin_failed: return -1; } +int gwavi_t::peak_chunk( FILE *fp, long int idx, char *fourcc, unsigned int *size ) +{ + long int cpos, fpos; + + cpos = ftell(fp); + + fpos = movi_fpos + idx; + + fseek( fp, fpos, SEEK_SET ); + + read_chars_bin(fp, fourcc, 4); + fourcc[4] = 0; + + read_uint( fp, *size ); + + //printf("Peak Chunk: %s %u\n", fourcc, *size ); + + fseek( fp, cpos, SEEK_SET ); + + return 0; +} + int -gwavi_t::write_index(FILE *out, int count, unsigned int *offsets) +gwavi_t::write_index(FILE *fp, int count, unsigned int *offsets) { long marker, t; unsigned int offset = 4; unsigned int r; + char fourcc[8]; if (offsets == 0) return -1; - if (write_chars_bin(out, "idx1", 4) == -1) { + if (write_chars_bin(fp, "idx1", 4) == -1) { (void)fprintf(stderr, "write_index: write_chars_bin) failed\n"); return -1; } - if ((marker = ftell(out)) == -1) { + if ((marker = ftell(fp)) == -1) { perror("write_index (ftell)"); return -1; } - if (write_int(out, 0) == -1) + if (write_int(fp, 0) == -1) goto write_int_failed; - for (t = 0; t < count; t++) { + for (t = 0; t < count; t++) + { + peak_chunk( fp, offset, fourcc, &r ); + if ((offsets[t] & 0x80000000) == 0) - write_chars(out, "00dc"); - else { - write_chars(out, "01wb"); + { + write_chars(fp, "00dc"); + //printf("Index: %u \n", offset ); + } + else + { + write_chars(fp, "01wb"); offsets[t] &= 0x7fffffff; } - if (write_int(out, 0x10) == -1) + if (write_int(fp, 0x10) == -1) goto write_int_failed; - if (write_int(out, offset) == -1) + if (write_int(fp, offset) == -1) goto write_int_failed; - if (write_int(out, offsets[t]) == -1) + if (write_int(fp, offsets[t]) == -1) goto write_int_failed; r = offsets[t] % WORD_SIZE; @@ -476,17 +512,17 @@ gwavi_t::write_index(FILE *out, int count, unsigned int *offsets) offset = offset + offsets[t] + 8 + r; } - if ((t = ftell(out)) == -1) { + if ((t = ftell(fp)) == -1) { perror("write_index (ftell)"); return -1; } - if (fseek(out, marker, SEEK_SET) == -1) { + if (fseek(fp, marker, SEEK_SET) == -1) { perror("write_index (fseek)"); return -1; } - if (write_int(out, (unsigned int)(t - marker - 4)) == -1) + if (write_int(fp, (unsigned int)(t - marker - 4)) == -1) goto write_int_failed; - if (fseek(out, t, SEEK_SET) == -1) { + if (fseek(fp, t, SEEK_SET) == -1) { perror("write_index (fseek)"); return -1; } diff --git a/src/drivers/Qt/avi/gwavi.cpp b/src/drivers/Qt/avi/gwavi.cpp index 80cf9f0d..ad60e0a9 100644 --- a/src/drivers/Qt/avi/gwavi.cpp +++ b/src/drivers/Qt/avi/gwavi.cpp @@ -75,6 +75,7 @@ gwavi_t::gwavi_t(void) memset( &stream_format_a, 0, sizeof(struct gwavi_stream_format_a_t) ); memset( fourcc, 0, sizeof(fourcc) ); marker = 0; + movi_fpos = 0; offsets_ptr = 0; offsets_len = 0; offsets_start = 0; @@ -240,7 +241,7 @@ gwavi_t::open(const char *filename, unsigned int width, unsigned int height, if (write_chars_bin(out, "AVI ", 4) == -1) goto write_chars_bin_failed; - if (write_avi_header_chunk() == -1) { + if (write_avi_header_chunk(out) == -1) { (void)fprintf(stderr, "gwavi_info: write_avi_header_chunk " "failed\n"); return -1; @@ -256,6 +257,8 @@ gwavi_t::open(const char *filename, unsigned int width, unsigned int height, (void)fprintf(stderr, "gwavi_info: write_int() failed\n"); return -1; } + movi_fpos = ftell(out); + if (write_chars_bin(out, "movi", 4) == -1) goto write_chars_bin_failed; @@ -331,6 +334,8 @@ gwavi_t::add_frame( unsigned char *buffer, size_t len) } } + //printf("Frame Offset: %li\n", ftell(out) - movi_fpos ); + offsets[offsets_ptr++] = (unsigned int)(len); if (write_chars_bin(out, "00dc", 4) == -1) { @@ -374,7 +379,8 @@ gwavi_t::add_audio( unsigned char *buffer, size_t len) size_t maxi_pad; /* in case audio bleeds over the 4 byte boundary */ size_t t; - if ( !buffer) { + if ( !buffer) + { (void)fputs("gwavi and/or buffer argument cannot be NULL", stderr); return -1; @@ -408,26 +414,32 @@ gwavi_t::add_audio( unsigned char *buffer, size_t len) offsets[offsets_ptr++] = (unsigned int)((len) | 0x80000000); - if (write_chars_bin(out,"01wb",4) == -1) { + if (write_chars_bin(out,"01wb",4) == -1) + { (void)fprintf(stderr, "gwavi_add_audio: write_chars_bin() " "failed\n"); return -1; } - if (write_int(out,(unsigned int)(len)) == -1) { + if (write_int(out,(unsigned int)(len)) == -1) + { (void)fprintf(stderr, "gwavi_add_audio: write_int() failed\n"); return -1; } - if ((t = fwrite(buffer, 1, len, out)) != len ) { + if ((t = fwrite(buffer, 1, len, out)) != len ) + { (void)fprintf(stderr, "gwavi_add_audio: fwrite() failed\n"); return -1; } for (t = 0; t < maxi_pad; t++) - if (fputc(0,out) == EOF) { + { + if (fputc(0,out) == EOF) + { (void)fprintf(stderr, "gwavi_add_audio: fputc() failed\n"); return -1; } + } stream_header_a.data_length += (unsigned int)(len + maxi_pad); @@ -452,14 +464,16 @@ gwavi_t::close(void) goto ftell_failed; if (fseek(out, marker, SEEK_SET) == -1) goto fseek_failed; - if (write_int(out, (unsigned int)(t - marker - 4)) == -1) { + if (write_int(out, (unsigned int)(t - marker - 4)) == -1) + { (void)fprintf(stderr, "gwavi_close: write_int() failed\n"); return -1; } if (fseek(out,t,SEEK_SET) == -1) goto fseek_failed; - if (write_index(out, offset_count, offsets) == -1) { + if (write_index(out, offset_count, offsets) == -1) + { (void)fprintf(stderr, "gwavi_close: write_index() failed\n"); return -1; } @@ -473,7 +487,7 @@ gwavi_t::close(void) goto ftell_failed; if (fseek(out, 12, SEEK_SET) == -1) goto fseek_failed; - if (write_avi_header_chunk() == -1) { + if (write_avi_header_chunk(out) == -1) { (void)fprintf(stderr, "gwavi_close: write_avi_header_chunk() " "failed\n"); return -1; @@ -485,7 +499,8 @@ gwavi_t::close(void) goto ftell_failed; if (fseek(out, 4, SEEK_SET) == -1) goto fseek_failed; - if (write_int(out, (unsigned int)(t - 8)) == -1) { + if (write_int(out, (unsigned int)(t - 8)) == -1) + { (void)fprintf(stderr, "gwavi_close: write_int() failed\n"); return -1; } @@ -682,9 +697,17 @@ unsigned int gwavi_t::readList(int lvl) size = listSize; if (read_chars_bin(in, listType, 4) == -1) + { return 0; + } listType[4] = 0; + + if ( strcmp( listType, "movi") == 0 ) + { + movi_fpos = ftell(in) - 4; + } + size -= 4; bytesRead += 4; @@ -793,6 +816,17 @@ unsigned int gwavi_t::readChunk(const char *id, int lvl) size -= ret; bytesRead += ret; } + else if ( strcmp( id, "idx1") == 0 ) + { + ret = readIndexBlock( chunkSize ); + + if ( ret == 0 ) + { + return 0; + } + size -= ret; + bytesRead += ret; + } while ( size >= WORD_SIZE ) { @@ -1060,3 +1094,49 @@ unsigned int gwavi_t::readStreamHeader(void) return sizeof(gwavi_AVIStreamHeader); } + +unsigned int gwavi_t::readIndexBlock( unsigned int chunkSize ) +{ + char chunkId[8]; + unsigned int size, flags, ofs, ckSize, bytesRead=0; + + size = chunkSize; + + while ( size >= 4 ) + { + if (read_chars_bin(in, chunkId, 4) == -1) + { + (void)fprintf(stderr, "readChunk: read_chars_bin() failed\n"); + return 0; + } + chunkId[4] = 0; + + if (read_uint(in, flags) == -1) + { + (void)fprintf(stderr, "readChunk: read_uint() failed\n"); + return 0; + } + + if (read_uint(in, ofs) == -1) + { + (void)fprintf(stderr, "readChunk: read_uint() failed\n"); + return 0; + } + + if (read_uint(in, ckSize) == -1) + { + (void)fprintf(stderr, "readChunk: read_uint() failed\n"); + return 0; + } + + printf(" Index: %s 0x%X ofs:%u size:%u\n", chunkId, flags, ofs, ckSize ); + + peak_chunk( in, ofs, chunkId, &ckSize ); + + printf("Peak Index: %s 0x%X ofs:%u size:%u\n", chunkId, flags, ofs, ckSize ); + + size -= 16; + bytesRead += 16; + } + return bytesRead; +} diff --git a/src/drivers/Qt/avi/gwavi.h b/src/drivers/Qt/avi/gwavi.h index 1b655ee0..582a2b63 100644 --- a/src/drivers/Qt/avi/gwavi.h +++ b/src/drivers/Qt/avi/gwavi.h @@ -182,36 +182,39 @@ class gwavi_t int offsets_len; long offsets_start; unsigned int *offsets; + long movi_fpos; int offset_count; int bits_per_pixel; char fourcc[8]; // helper functions - int write_avi_header(FILE *out, struct gwavi_header_t *avi_header); - int write_stream_header(FILE *out, + int write_avi_header(FILE *fp, struct gwavi_header_t *avi_header); + int write_stream_header(FILE *fp, struct gwavi_stream_header_t *stream_header); - int write_stream_format_v(FILE *out, + int write_stream_format_v(FILE *fp, struct gwavi_stream_format_v_t *stream_format_v); - int write_stream_format_a(FILE *out, + int write_stream_format_a(FILE *fp, struct gwavi_stream_format_a_t *stream_format_a); - int write_avi_header_chunk(void); - int write_index(FILE *out, int count, unsigned int *offsets); + int write_avi_header_chunk( FILE *fp ); + int write_index(FILE *fp, int count, unsigned int *offsets); int check_fourcc(const char *fourcc); - int write_int(FILE *out, unsigned int n); - int write_short(FILE *out, unsigned int n); - int write_chars(FILE *out, const char *s); - int write_chars_bin(FILE *out, const char *s, int count); + int write_int(FILE *fp, unsigned int n); + int write_short(FILE *fp, unsigned int n); + int write_chars(FILE *fp, const char *s); + int write_chars_bin(FILE *fp, const char *s, int count); + int peak_chunk( FILE *fp, long int idx, char *fourcc, unsigned int *size ); - int read_int(FILE *out, int &n); - int read_uint(FILE *out, unsigned int &n); - int read_short(FILE *in, int16_t &n); - int read_short(FILE *out, int &n); - int read_ushort(FILE *in, uint16_t &n); - int read_chars_bin(FILE *in, char *s, int count); + int read_int(FILE *fp, int &n); + int read_uint(FILE *fp, unsigned int &n); + int read_short(FILE *fp, int16_t &n); + int read_short(FILE *fp, int &n); + int read_ushort(FILE *fp, uint16_t &n); + int read_chars_bin(FILE *fp, char *s, int count); unsigned int readList(int lvl); unsigned int readChunk(const char *id, int lvl); unsigned int readAviHeader(void); unsigned int readStreamHeader(void); + unsigned int readIndexBlock( unsigned int chunkSize ); }; #endif /* ndef H_GWAVI */