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 / file.C < prev    next >
C/C++ Source or Header  |  2000-11-29  |  4KB  |  217 lines

  1. #include "asset.h"
  2. #include "file.h"
  3. #include "filemov.h"
  4. #include "filempeg.h"
  5.  
  6.  
  7. File::File(MainWindow *mwindow)
  8. {
  9.     this->mwindow = mwindow;
  10.     file = 0;
  11.     asset = 0;
  12.     cpus = 1;
  13.     use_mmx = 1;
  14. }
  15.  
  16. File::~File()
  17. {
  18.     close_file();
  19. }
  20.  
  21. int File::set_processors(int cpus)
  22. {
  23.     this->cpus = cpus;
  24.     if(file) file->set_cpus(cpus);
  25.     return 0;
  26. }
  27.  
  28. int File::set_mmx(int use_mmx)
  29. {
  30.     this->use_mmx = use_mmx;
  31.     if(file) file->set_mmx(use_mmx);
  32.     return 0;
  33. }
  34.  
  35. int File::set_prebuffer(long size)
  36. {
  37.     this->prebuffer_size = size;
  38.     return 0;
  39. }
  40.  
  41. int File::open_file(Asset *asset)
  42. {
  43.     this->asset = asset;
  44.     this->mwindow = mwindow;
  45.  
  46. // get the format now
  47.     FILE *stream;
  48.     if(!(stream = fopen(asset->path, "rb")))
  49.     {
  50. // file not found
  51.         return 1;
  52.     }
  53.  
  54. // ============================== Check formats
  55. // add new formats here
  56.     if(mpeg3_check_sig(asset->path))
  57.     {
  58.         fclose(stream);
  59.         file = new FileMPEG(asset, this);
  60.     }
  61.     else
  62.     if(quicktime_check_sig(asset->path))
  63.     {
  64. // MOV file
  65. // should be last because quicktime lacks a magic number
  66.         fclose(stream);
  67.         file = new FileMOV(asset, this);
  68.     }
  69.     else
  70.     {
  71.         fclose(stream);
  72.         return 2;
  73.     }
  74.  
  75.     int result = file->open_file();
  76.     total_frames = get_video_length();
  77.     total_samples = get_audio_length();
  78.     if(result)
  79.     {
  80. // failure
  81.         delete file;
  82.         file = 0;
  83.     }
  84.     return result;
  85. }
  86.  
  87. int File::close_file()
  88. {
  89.     if(file) 
  90.     {
  91.         file->close_file();
  92.         delete file;
  93.     }
  94.  
  95.     file = 0;
  96.     asset = 0;
  97.     return 0;
  98. }
  99.  
  100. long File::get_audio_length() { return file->get_audio_length(); }
  101.  
  102. long File::get_video_length() { return file->get_video_length(); }
  103.  
  104. long File::get_video_position() { return file->get_video_position(); }
  105.  
  106. long File::get_audio_position() { return file->get_audio_position(); }
  107.  
  108. int File::get_position(double &percentage, double &seconds)
  109. {
  110.     return file->get_position(percentage, seconds);
  111. }
  112.  
  113. int File::end_of_audio()
  114. {
  115.     return file->end_of_audio();
  116. }
  117.  
  118. int File::end_of_video()
  119. {
  120.     return file->end_of_video();
  121. }
  122.  
  123. int File::set_position(double percentage)
  124. {
  125.     return file->set_position(percentage);
  126. }
  127.  
  128. int File::set_audio_position(long x) 
  129. {
  130.     file->set_audio_position(x); 
  131.     return 0;
  132. }
  133.  
  134. int File::set_video_position(long x) 
  135.     if(x < total_frames)
  136.         file->set_video_position(x);
  137.     else
  138.         file->set_video_position(total_frames - 1);
  139.     return 0;
  140. }
  141.  
  142. int File::set_audio_stream(int stream)
  143. {
  144.     if(stream < asset->audio_streams)
  145.         return file->set_audio_stream(stream);
  146.     return -1;
  147. }
  148.  
  149. int File::set_video_stream(int stream)
  150. {
  151.     if(stream < asset->video_streams)
  152.         return file->set_video_stream(stream);
  153.     return -1;
  154. }
  155.  
  156. int File::drop_frames(int frames)
  157. {
  158.     return file->drop_frames(frames);
  159. }
  160.  
  161. int File::frame_back()
  162. {
  163.     return file->frame_back();
  164. }
  165.  
  166.  
  167. int File::lock_read()
  168. {
  169.     read_lock.lock();
  170.     return 0;
  171. }
  172.  
  173. int File::unlock_read()
  174. {
  175.     read_lock.unlock();
  176.     return 0;
  177. }
  178.  
  179. int File::read_audio(char *buffer, long len)
  180. {
  181.     int result = 0;
  182.     if(file) result = file->read_audio(buffer, len);
  183.     return result;
  184. }
  185.  
  186. int File::yuv_copy_possible()
  187. {
  188.     if(file) return file->yuv_copy_possible();
  189.     return 0;
  190. }
  191.  
  192. int File::frame_buffer_copy_possible(int color_model)
  193. {
  194.     if(file) return file->frame_buffer_copy_possible(color_model);
  195.     return 0;
  196. }
  197.  
  198. int File::read_yuv_buffer(char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h)
  199. {
  200.     if(file) return file->read_yuv_buffer(y_output, u_output, v_output, in_x, in_y, in_w, in_h);
  201.     return 1;
  202. }
  203.  
  204. int File::read_frame_buffer(unsigned char **frame_buffer, int w, int h, int bitmap_color_model)
  205. {
  206.     if(file) return file->read_frame_buffer(frame_buffer, w, h, bitmap_color_model);
  207.     return 1;
  208. }
  209.  
  210. int File::read_frame(unsigned char *frame)
  211. {
  212.     int result = 1;
  213.     if(file) result = file->read_frame(frame);
  214.     return result;
  215. }
  216.