00001 #ifndef FILETHREAD_H 00002 #define FILETHREAD_H 00003 00004 #include "condition.inc" 00005 #include "file.inc" 00006 #include "mutex.inc" 00007 #include "thread.h" 00008 #include "vframe.inc" 00009 00010 00011 // This allows the file hander to write in the background without 00012 // blocking the write commands. 00013 // Used for recording. 00014 00015 00016 // Container for read frames 00017 class FileThreadFrame 00018 { 00019 public: 00020 FileThreadFrame(); 00021 ~FileThreadFrame(); 00022 00023 // Frame position in native framerate 00024 int64_t position; 00025 int layer; 00026 VFrame *frame; 00027 }; 00028 00029 class FileThread : public Thread 00030 { 00031 public: 00032 FileThread(File *file, int do_audio, int do_video); 00033 ~FileThread(); 00034 00035 void create_objects(File *file, 00036 int do_audio, 00037 int do_video); 00038 void delete_objects(); 00039 void reset(); 00040 00041 00042 // ============================== writing section ============================== 00043 int start_writing(); 00044 // Allocate the buffers and start loop for writing. 00045 // compressed - if 1 write_compressed_frames is called in the file 00046 // - if 0 write_frames is called 00047 int start_writing(long buffer_size, 00048 int color_model, 00049 int ring_buffers, 00050 int compressed); 00051 int stop_writing(); 00052 00053 00054 00055 00056 // ================================ reading section ============================ 00057 // Allocate buffers and start loop for reading 00058 int start_reading(); 00059 int stop_reading(); 00060 00061 int read_frame(VFrame *frame); 00062 // Set native framerate. 00063 // Called by File::set_video_position. 00064 int set_video_position(int64_t position); 00065 int set_layer(int layer); 00066 int read_buffer(); 00067 int64_t get_memory_usage(); 00068 00069 // write data into next available buffer 00070 int write_buffer(long size); 00071 // get pointer to next buffer to be written and lock it 00072 double** get_audio_buffer(); 00073 // get pointer to next frame to be written and lock it 00074 VFrame*** get_video_buffer(); 00075 00076 void run(); 00077 int swap_buffer(); 00078 00079 double ***audio_buffer; 00080 // (VFrame*)(VFrame array *)(Track *)[ring buffer] 00081 VFrame ****video_buffer; 00082 long *output_size; // Number of frames or samples to write 00083 // Not used 00084 int *is_compressed; // Whether to use the compressed data in the frame 00085 Condition **output_lock, **input_lock; 00086 // Lock access to the file to allow it to be changed without stopping the loop 00087 Mutex *file_lock; 00088 int current_buffer; 00089 int local_buffer; 00090 int *last_buffer; // last_buffer[ring buffer] 00091 int return_value; 00092 int do_audio; 00093 int do_video; 00094 File *file; 00095 int ring_buffers; 00096 int buffer_size; // Frames or samples per ring buffer 00097 // Color model of frames 00098 int color_model; 00099 // Whether to use the compressed data in the frame 00100 int compressed; 00101 00102 // Mode of operation 00103 int is_reading; 00104 int is_writing; 00105 int done; 00106 00107 // For the reading mode, the thread reads continuously from the given 00108 // point until stopped. 00109 // Maximum frames to preload 00110 #define MAX_READ_FRAMES 4 00111 // Total number of frames preloaded 00112 int total_frames; 00113 // Allocated frames 00114 FileThreadFrame *read_frames[MAX_READ_FRAMES]; 00115 // If the seeking pattern isn't optimal for asynchronous reading, this is 00116 // set to 1 to stop reading. 00117 int disable_read; 00118 // Thread waits on this if the maximum frames have been read. 00119 Condition *read_wait_lock; 00120 // read_frame waits on this if the thread is running. 00121 Condition *user_wait_lock; 00122 // Lock access to read_frames 00123 Mutex *frame_lock; 00124 // Position of first frame in read_frames. 00125 // Set by set_video_position and read_frame only. 00126 // Position is in native framerate. 00127 int64_t start_position; 00128 // Position to read next frame from 00129 int64_t read_position; 00130 // Last layer a frame was read from 00131 int layer; 00132 }; 00133 00134 00135 00136 #endif
1.5.5