4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "condition.inc"
28 #include "samples.inc"
33 // This allows the file hander to write in the background without
34 // blocking the write commands.
35 // Used for recording.
38 // Container for read frames
45 // Frame position in native framerate
52 class FileThread : public Thread
55 FileThread(File *file, int do_audio, int do_video);
58 void create_objects(File *file,
61 void delete_objects();
65 // ============================== writing section ==============================
67 // Allocate the buffers and start loop for writing.
68 // compressed - if 1 write_compressed_frames is called in the file
69 // - if 0 write_frames is called
70 int start_writing(long buffer_size,
79 // ================================ reading section ============================
80 // Allocate buffers and start loop for reading
84 int read_frame(VFrame *frame);
85 // Set native framerate.
86 // Called by File::set_video_position.
87 int set_video_position(int64_t position);
88 int set_layer(int layer);
90 int64_t get_memory_usage();
92 // write data into next available buffer
93 int write_buffer(long size);
94 // get pointer to next buffer to be written and lock it
95 Samples** get_audio_buffer();
96 // get pointer to next frame to be written and lock it
97 VFrame*** get_video_buffer();
98 // get pointer to last video buffer returned without advancing it
99 VFrame*** get_last_video_buffer();
104 // [ring_buffer][channels][Samples*]
105 Samples ***audio_buffer;
106 // [ring buffer](Track *)(VFrame array *)(VFrame*)
107 VFrame ****video_buffer;
108 long *output_size; // Number of frames or samples to write
110 int *is_compressed; // Whether to use the compressed data in the frame
111 Condition **output_lock, **input_lock;
112 // Lock access to the file to allow it to be changed without stopping the loop
116 int *last_buffer; // last_buffer[ring buffer]
122 int buffer_size; // Frames or samples per ring buffer
123 // Color model of frames
125 // Whether to use the compressed data in the frame
133 // For the reading mode, the thread reads continuously from the given
134 // point until stopped.
135 // Maximum frames to preload
136 #define MAX_READ_FRAMES 4
137 // Total number of frames preloaded
140 FileThreadFrame *read_frames[MAX_READ_FRAMES];
141 // If the seeking pattern isn't optimal for asynchronous reading, this is
142 // set to 1 to stop reading.
144 // Thread waits on this if the maximum frames have been read.
145 Condition *read_wait_lock;
146 // read_frame waits on this if the thread is running.
147 Condition *user_wait_lock;
148 // Lock access to read_frames
150 // Position of first frame in read_frames.
151 // Set by set_video_position and read_frame only.
152 // Position is in native framerate.
153 int64_t start_position;
154 // Position to read next frame from
155 int64_t read_position;
156 // Last layer a frame was read from