trunk/src/lib/util/aviio.c
| r20683 | r20684 | |
| 54 | 54 | #define FOUR_GB ((UINT64)1 << 32) |
| 55 | 55 | |
| 56 | 56 | #define MAX_SOUND_CHANNELS 2 |
| 57 | | #define SOUND_BUFFER_MSEC 2000 /* microseconds of sond buffering */ |
| 57 | #define SOUND_BUFFER_MSEC 2000 /* milliseconds of sound buffering */ |
| 58 | 58 | |
| 59 | 59 | #define CHUNKTYPE_RIFF AVI_FOURCC('R','I','F','F') |
| 60 | 60 | #define CHUNKTYPE_LIST AVI_FOURCC('L','I','S','T') |
| r20683 | r20684 | |
| 541 | 541 | |
| 542 | 542 | |
| 543 | 543 | /*------------------------------------------------- |
| 544 | | avi_create - create a new QuickTime movie file |
| 544 | avi_create - create a new AVI movie file |
| 545 | 545 | -------------------------------------------------*/ |
| 546 | 546 | |
| 547 | 547 | avi_error avi_create(const char *filename, const avi_movie_info *info, avi_file **file) |
| r20683 | r20684 | |
| 648 | 648 | |
| 649 | 649 | |
| 650 | 650 | /*------------------------------------------------- |
| 651 | | avi_close - close a QuickTime movie file |
| 651 | avi_close - close an AVI movie file |
| 652 | 652 | -------------------------------------------------*/ |
| 653 | 653 | |
| 654 | 654 | avi_error avi_close(avi_file *file) |
| r20683 | r20684 | |
| 980 | 980 | if (avierr != AVIERR_NONE) |
| 981 | 981 | return avierr; |
| 982 | 982 | |
| 983 | /* write the data */ |
| 984 | avierr = chunk_write(file, get_chunkid_for_stream(file, stream), file->tempbuffer, maxlength); |
| 985 | if (avierr != AVIERR_NONE) |
| 986 | return avierr; |
| 987 | |
| 983 | 988 | /* set the info for this new chunk */ |
| 984 | | avierr = set_stream_chunk_info(stream, stream->chunks, file->writeoffs, maxlength + 8); |
| 989 | avierr = set_stream_chunk_info(stream, stream->chunks, file->writeoffs - maxlength - 8, maxlength + 8); |
| 985 | 990 | if (avierr != AVIERR_NONE) |
| 986 | 991 | return avierr; |
| 992 | |
| 987 | 993 | stream->samples = file->info.video_numsamples = stream->chunks; |
| 988 | 994 | |
| 989 | | /* write the data */ |
| 990 | | return chunk_write(file, get_chunkid_for_stream(file, stream), file->tempbuffer, maxlength); |
| 995 | return AVIERR_NONE; |
| 991 | 996 | } |
| 992 | 997 | |
| 993 | 998 | |
| r20683 | r20684 | |
| 1026 | 1031 | if (avierr != AVIERR_NONE) |
| 1027 | 1032 | return avierr; |
| 1028 | 1033 | |
| 1034 | /* write the data */ |
| 1035 | avierr = chunk_write(file, get_chunkid_for_stream(file, stream), file->tempbuffer, maxlength); |
| 1036 | if (avierr != AVIERR_NONE) |
| 1037 | return avierr; |
| 1038 | |
| 1029 | 1039 | /* set the info for this new chunk */ |
| 1030 | | avierr = set_stream_chunk_info(stream, stream->chunks, file->writeoffs, maxlength + 8); |
| 1040 | avierr = set_stream_chunk_info(stream, stream->chunks, file->writeoffs - maxlength - 8, maxlength + 8); |
| 1031 | 1041 | if (avierr != AVIERR_NONE) |
| 1032 | 1042 | return avierr; |
| 1043 | |
| 1033 | 1044 | stream->samples = file->info.video_numsamples = stream->chunks; |
| 1034 | 1045 | |
| 1035 | | /* write the data */ |
| 1036 | | return chunk_write(file, get_chunkid_for_stream(file, stream), file->tempbuffer, maxlength); |
| 1046 | return AVIERR_NONE; |
| 1037 | 1047 | } |
| 1038 | 1048 | |
| 1039 | 1049 | |
| r20683 | r20684 | |
| 2210 | 2220 | { |
| 2211 | 2221 | avi_stream *stream = get_audio_stream(file, 0, NULL); |
| 2212 | 2222 | avi_error avierr; |
| 2213 | | UINT32 chunknum; |
| 2214 | 2223 | UINT32 length; |
| 2215 | 2224 | |
| 2216 | 2225 | /* skip if no audio stream */ |
| r20683 | r20684 | |
| 2224 | 2233 | length = framenum_to_samplenum(file, framenum + 1 + file->soundbuf_frames) - framenum_to_samplenum(file, framenum + file->soundbuf_frames); |
| 2225 | 2234 | length *= stream->channels * sizeof(INT16); |
| 2226 | 2235 | |
| 2227 | | /* set the info for this new chunk */ |
| 2228 | | chunknum = stream->chunks; |
| 2229 | | avierr = set_stream_chunk_info(stream, chunknum, file->writeoffs, length + 8); |
| 2236 | /* then do the initial write */ |
| 2237 | avierr = chunk_write(file, get_chunkid_for_stream(file, stream), file->soundbuf, length); |
| 2230 | 2238 | if (avierr != AVIERR_NONE) |
| 2231 | 2239 | return avierr; |
| 2232 | 2240 | |
| 2233 | | /* then do the initial write */ |
| 2234 | | return chunk_overwrite(file, get_chunkid_for_stream(file, stream), file->soundbuf, length, &stream->chunk[chunknum].offset, TRUE); |
| 2241 | /* set the info for this new chunk */ |
| 2242 | return set_stream_chunk_info(stream, stream->chunks, file->writeoffs - length - 8, length + 8); |
| 2235 | 2243 | } |
| 2236 | 2244 | |
| 2237 | 2245 | |