4 #include "condition.inc"
11 // This allows the file hander to write in the background without
12 // blocking the write commands.
13 // Used for recording.
16 // Container for read frames
23 // Frame position in native framerate
29 class FileThread
: public Thread
32 FileThread(File
*file
, int do_audio
, int do_video
);
35 void create_objects(File
*file
,
38 void delete_objects();
42 // ============================== writing section ==============================
44 // Allocate the buffers and start loop for writing.
45 // compressed - if 1 write_compressed_frames is called in the file
46 // - if 0 write_frames is called
47 int start_writing(long buffer_size
,
56 // ================================ reading section ============================
57 // Allocate buffers and start loop for reading
61 int read_frame(VFrame
*frame
);
62 // Set native framerate.
63 // Called by File::set_video_position.
64 int set_video_position(int64_t position
);
65 int set_layer(int layer
);
67 int64_t get_memory_usage();
69 // write data into next available buffer
70 int write_buffer(long size
);
71 // get pointer to next buffer to be written and lock it
72 double** get_audio_buffer();
73 // get pointer to next frame to be written and lock it
74 VFrame
*** get_video_buffer();
79 double ***audio_buffer
;
80 // (VFrame*)(VFrame array *)(Track *)[ring buffer]
81 VFrame
****video_buffer
;
82 long *output_size
; // Number of frames or samples to write
84 int *is_compressed
; // Whether to use the compressed data in the frame
85 Condition
**output_lock
, **input_lock
;
86 // Lock access to the file to allow it to be changed without stopping the loop
90 int *last_buffer
; // last_buffer[ring buffer]
96 int buffer_size
; // Frames or samples per ring buffer
97 // Color model of frames
99 // Whether to use the compressed data in the frame
107 // For the reading mode, the thread reads continuously from the given
108 // point until stopped.
109 // Maximum frames to preload
110 #define MAX_READ_FRAMES 4
111 // Total number of frames preloaded
114 FileThreadFrame
*read_frames
[MAX_READ_FRAMES
];
115 // If the seeking pattern isn't optimal for asynchronous reading, this is
116 // set to 1 to stop reading.
118 // Thread waits on this if the maximum frames have been read.
119 Condition
*read_wait_lock
;
120 // read_frame waits on this if the thread is running.
121 Condition
*user_wait_lock
;
122 // Lock access to read_frames
124 // Position of first frame in read_frames.
125 // Set by set_video_position and read_frame only.
126 // Position is in native framerate.
127 int64_t start_position
;
128 // Position to read next frame from
129 int64_t read_position
;
130 // Last layer a frame was read from