r870: Merge 2.1:
[cinelerra_cv.git] / cinelerra / filebase.C
bloba17526fd49e55db2425b7b68936cd55b7e6900b6
1 #include "asset.h"
2 #include "assets.h"
3 #include "byteorder.h"
4 #include "colormodels.h"
5 #include "file.h"
6 #include "filebase.h"
7 #include "overlayframe.h"
8 #include "sizes.h"
10 #include <stdlib.h>
12 FileBase::FileBase(Asset *asset, File *file)
14         this->file = file;
15         this->asset = asset;
16         internal_byte_order = get_byte_order();
17         init_ima4();
18         reset_parameters();
19         overlayer = new OverlayFrame;
22 FileBase::~FileBase()
24         if(audio_buffer_in) delete [] audio_buffer_in;
25         if(audio_buffer_out) delete [] audio_buffer_out;
26         if(video_buffer_in) delete [] video_buffer_in;
27         if(video_buffer_out) delete [] video_buffer_out;
28         if(row_pointers_in) delete [] row_pointers_in;
29         if(row_pointers_out) delete [] row_pointers_out;
30         if(float_buffer) delete [] float_buffer;
31         delete overlayer;
32         delete_ima4();
35 int FileBase::close_file()
37         if(audio_buffer_in) delete [] audio_buffer_in;
38         if(audio_buffer_out) delete [] audio_buffer_out;
39         if(video_buffer_in) delete [] video_buffer_in;
40         if(video_buffer_out) delete [] video_buffer_out;
41         if(row_pointers_in) delete [] row_pointers_in;
42         if(row_pointers_out) delete [] row_pointers_out;
43         if(float_buffer) delete [] float_buffer;
44         close_file_derived();
45         reset_parameters();
46         delete_ima4();
49 int FileBase::set_dither()
51         dither = 1;
52         return 0;
55 int FileBase::reset_parameters()
57         dither = 0;
58         audio_buffer_in = 0;
59         video_buffer_in = 0;
60         audio_buffer_out = 0;
61         video_buffer_out = 0;
62         float_buffer = 0;
63         row_pointers_in = 0;
64         row_pointers_out = 0;
65         prev_buffer_position = -1;
66         prev_frame_position = -1;
67         prev_len = 0;
68         prev_bytes = 0;
69         prev_track = -1;
70         prev_layer = -1;
71         ulawtofloat_table = 0;
72         floattoulaw_table = 0;
73         rd = wr = 0;
75         delete_ulaw_tables();
76         reset_parameters_derived();
79 int FileBase::get_mode(char *mode, int rd, int wr)
81         if(rd && !wr) sprintf(mode, "rb");
82         else
83         if(!rd && wr) sprintf(mode, "wb");
84         else
85         if(rd && wr)
86         {
87                 int exists = 0;
88                 FILE *stream;
90                 if(stream = fopen(asset->path, "rb")) 
91                 {
92                         exists = 1; 
93                         fclose(stream); 
94                 }
96                 if(exists) sprintf(mode, "rb+");
97                 else
98                 sprintf(mode, "wb+");
99         }
111 // ======================================= audio codecs
113 int FileBase::get_video_buffer(unsigned char **buffer, int depth)
115 // get a raw video buffer for writing or compression by a library
116         if(!*buffer)
117         {
118 // Video compression is entirely done in the library.
119                 int64_t bytes = asset->width * asset->height * depth;
120                 *buffer = new unsigned char[bytes];
121         }
122         return 0;
125 int FileBase::get_row_pointers(unsigned char *buffer, unsigned char ***pointers, int depth)
127 // This might be fooled if a new VFrame is created at the same address with a different height.
128         if(*pointers && (*pointers)[0] != &buffer[0])
129         {
130                 delete [] *pointers;
131                 *pointers = 0;
132         }
134         if(!*pointers)
135         {
136                 *pointers = new unsigned char*[asset->height];
137                 for(int i = 0; i < asset->height; i++)
138                 {
139                         (*pointers)[i] = &buffer[i * asset->width * depth / 8];
140                 }
141         }
144 int FileBase::match4(char *in, char *out)
146         if(in[0] == out[0] &&
147                 in[1] == out[1] &&
148                 in[2] == out[2] &&
149                 in[3] == out[3])
150                 return 1;
151         else
152                 return 0;
155 int FileBase::search_render_strategies(ArrayList<int>* render_strategies, int render_strategy)
157         int i;
158         for(i = 0; i < render_strategies->total; i++)
159                 if(render_strategies->values[i] == render_strategy) return 1;
161         return 0;