home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek 6
/
Geek-006.iso
/
linux
/
video
/
xmovie-1.5.3.tar.gz
/
xmovie-1.5.3.tar
/
xmovie-1.5.3
/
xmovie
/
filemov.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-11-29
|
6KB
|
280 lines
#include "asset.h"
#include "colormodels.h"
#include "file.h"
#include "filemov.h"
#include "vframe.h"
#include <string.h>
#define MAX(x, y) ((x) > (y) ? (x) : (y))
FileMOV::FileMOV(Asset *asset, File *file)
: FileBase(asset, file)
{
reset_parameters();
asset->format = MOV;
asset->byte_order = 0;
}
FileMOV::~FileMOV()
{
close_file();
}
int FileMOV::reset_parameters_derived()
{
file = 0;
return 0;
}
int FileMOV::open_file()
{
if(!(file = quicktime_open(asset->path, 1, 0)))
{
perror("FileMOV::open_file");
return 1;
}
quicktime_set_preload(file, FileBase::file->prebuffer_size);
quicktime_set_cpus(file, FileBase::file->cpus);
read_header();
if(!asset->video_data && !asset->audio_data)
{
quicktime_close(file);
return 3;
}
return 0;
}
int FileMOV::close_file_derived()
{
if(file) quicktime_close(file);
file = 0;
return 0;
}
int FileMOV::read_header()
{
// determine if the audio can be read before declaring audio data
if(quicktime_has_audio(file))
if(quicktime_supported_audio(file, 0))
asset->audio_data = 1;
else
printf("FileMOV::read_header: unsupported audio codec\n");
if(asset->audio_data)
{
asset->audio_streams = 1;
asset->channels = 0;
asset->channels = quicktime_track_channels(file, 0);
asset->rate = quicktime_sample_rate(file, 0);
asset->bits = quicktime_audio_bits(file, 0);
char *compressor = quicktime_audio_compressor(file, 0);
if(quicktime_supported_audio(file, 0))
{
asset->bits = 16;
asset->signed_ = 1;
asset->byte_order = internal_byte_order;
}
else
if(match4(compressor, "raw ")) asset->signed_ = 0;
else
if(match4(compressor, "twos")) asset->signed_ = 1;
else
printf("FileMOV::read_header: unsupported audio codec\n");
}
// determine if the video can be read before declaring video data
if(quicktime_has_video(file))
if(quicktime_supported_video(file, 0))
asset->video_data = 1;
else
printf("FileMOV::read_header: unsupported video codec\n");
if(asset->video_data)
{
asset->video_streams = 1;
asset->width = quicktime_video_width(file, 0);
asset->height = quicktime_video_height(file, 0);
asset->frame_rate = quicktime_frame_rate(file, 0);
char *compressor = quicktime_video_compressor(file, 0);
asset->compression[0] = compressor[0];
asset->compression[1] = compressor[1];
asset->compression[2] = compressor[2];
asset->compression[3] = compressor[3];
}
return 0;
}
long FileMOV::get_audio_length()
{
long result = quicktime_audio_length(file, 0);
return result;
}
long FileMOV::get_video_length()
{
long result = quicktime_video_length(file, 0);
return result;
}
int FileMOV::get_position(double &percentage, double &seconds)
{
float apercentage = 0, aseconds = 0;
float vpercentage = 0, vseconds = 0;
if(file)
{
if(asset->audio_data)
{
apercentage = (double)get_audio_position() / get_audio_length();
aseconds = (double)get_audio_position() / asset->rate;
}
if(asset->video_data)
{
vpercentage = (double)get_video_position() / get_video_length();
vseconds = (double)get_video_position() / asset->frame_rate;
}
percentage = MAX(apercentage, vpercentage);
seconds = MAX(aseconds, vseconds);
}
return 0;
}
long FileMOV::get_video_position()
{
return quicktime_video_position(file, 0);
}
long FileMOV::get_audio_position()
{
return quicktime_audio_position(file, 0);
}
int FileMOV::end_of_audio()
{
return quicktime_audio_position(file, 0) >= quicktime_audio_length(file, 0);
}
int FileMOV::end_of_video()
{
return quicktime_video_position(file, 0) >= quicktime_video_length(file, 0);
}
int FileMOV::set_position(double percentage)
{
int result = 0;
result |= set_audio_position((int)(percentage * get_audio_length()));
result |= set_video_position((int)(percentage * get_video_length()));
return result;
}
int FileMOV::set_audio_position(long x)
{
audio_position = x;
return quicktime_set_audio_position(file, x, 0);
}
int FileMOV::set_video_position(long x)
{
video_position = x;
return quicktime_set_video_position(file, x, 0);
}
int FileMOV::drop_frames(int frames)
{
video_position += frames;
return quicktime_set_video_position(file, video_position, 0);
}
int FileMOV::frame_back()
{
if(asset->video_data)
{
video_position--;
audio_position = 0;
}
else
{
video_position = 0;
audio_position -= 44100;
}
quicktime_set_video_position(file, video_position, 0);
quicktime_set_audio_position(file, audio_position, 0);
return 0;
}
#define IMPORT1 \
for(int i = 0; i < asset->height; i++) \
{
#define IMPORT2 \
}
int FileMOV::read_frame(unsigned char *frame)
{
int i, result;
unsigned char **row_pointers;
row_pointers = new unsigned char*[asset->height];
for(i = 0; i < asset->height; i++)
row_pointers[i] = &frame[i * asset->width * 3];
result = quicktime_decode_video(file, row_pointers, 0);
delete row_pointers;
video_position++;
return result;
}
int FileMOV::read_audio(char *buffer, long len)
{
if(quicktime_supported_audio(file, 0))
{
int channel;
int i, j;
int result = 0;
get_read_buffer(len);
for(channel = 0; channel < asset->channels && !result; channel++)
{
//printf("FileMOV::read_raw %d\n", channel);
quicktime_set_audio_position(file, audio_position, 0);
result = quicktime_decode_audio(file, read_buffer, 0, len, channel);
BCBASE_INT16 *output_ptr = (BCBASE_INT16*)buffer + channel;
BCBASE_INT16 *input_ptr = (BCBASE_INT16*)read_buffer;
BCBASE_INT16 *input_end = input_ptr + len;
// Interlace the audio for the sound driver.
while(input_ptr < input_end)
{
*output_ptr = *input_ptr++;
output_ptr += asset->channels;
}
}
}
audio_position += len;
return 0;
}
int FileMOV::load_into_ram()
{
if(asset->video_data)
{
// quicktime_cache_frames(file, 0);
}
return 0;
}