r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / filebase.C
blob6eac20d57b4fa12f75c6e90845c428520fe902e9
1 #include "assets.h"
2 #include "byteorder.h"
3 #include "colormodels.h"
4 #include "file.h"
5 #include "filebase.h"
6 #include "overlayframe.h"
7 #include "sizes.h"
9 #include <stdlib.h>
11 FileBase::FileBase(Asset *asset, File *file)
13         this->file = file;
14         this->asset = asset;
15         internal_byte_order = get_byte_order();
16         init_ima4();
17         reset_parameters();
18         overlayer = new OverlayFrame;
21 FileBase::~FileBase()
23         if(audio_buffer_in) delete [] audio_buffer_in;
24         if(audio_buffer_out) delete [] audio_buffer_out;
25         if(video_buffer_in) delete [] video_buffer_in;
26         if(video_buffer_out) delete [] video_buffer_out;
27         if(row_pointers_in) delete [] row_pointers_in;
28         if(row_pointers_out) delete [] row_pointers_out;
29         if(float_buffer) delete [] float_buffer;
30         delete overlayer;
31         delete_ima4();
34 int FileBase::close_file()
36         if(audio_buffer_in) delete [] audio_buffer_in;
37         if(audio_buffer_out) delete [] audio_buffer_out;
38         if(video_buffer_in) delete [] video_buffer_in;
39         if(video_buffer_out) delete [] video_buffer_out;
40         if(row_pointers_in) delete [] row_pointers_in;
41         if(row_pointers_out) delete [] row_pointers_out;
42         if(float_buffer) delete [] float_buffer;
43         close_file_derived();
44         reset_parameters();
45         delete_ima4();
48 int FileBase::set_dither()
50         dither = 1;
51         return 0;
54 int FileBase::reset_parameters()
56         dither = 0;
57         audio_buffer_in = 0;
58         video_buffer_in = 0;
59         audio_buffer_out = 0;
60         video_buffer_out = 0;
61         float_buffer = 0;
62         row_pointers_in = 0;
63         row_pointers_out = 0;
64         prev_buffer_position = -1;
65         prev_frame_position = -1;
66         prev_len = 0;
67         prev_bytes = 0;
68         prev_track = -1;
69         prev_layer = -1;
70         ulawtofloat_table = 0;
71         floattoulaw_table = 0;
73         delete_ulaw_tables();
74         reset_parameters_derived();
77 int FileBase::get_mode(char *mode, int rd, int wr)
79         if(rd && !wr) sprintf(mode, "rb");
80         else
81         if(!rd && wr) sprintf(mode, "wb");
82         else
83         if(rd && wr)
84         {
85                 int exists = 0;
86                 FILE *stream;
88                 if(stream = fopen(asset->path, "rb")) 
89                 {
90                         exists = 1; 
91                         fclose(stream); 
92                 }
94                 if(exists) sprintf(mode, "rb+");
95                 else
96                 sprintf(mode, "wb+");
97         }
109 // ======================================= audio codecs
111 int FileBase::get_video_buffer(unsigned char **buffer, int depth)
113 // get a raw video buffer for writing or compression by a library
114         if(!*buffer)
115         {
116 // Video compression is entirely done in the library.
117                 int64_t bytes = asset->width * asset->height * depth;
118                 *buffer = new unsigned char[bytes];
119         }
120         return 0;
123 int FileBase::get_row_pointers(unsigned char *buffer, unsigned char ***pointers, int depth)
125 // This might be fooled if a new VFrame is created at the same address with a different height.
126         if(*pointers && (*pointers)[0] != &buffer[0])
127         {
128                 delete [] *pointers;
129                 *pointers = 0;
130         }
132         if(!*pointers)
133         {
134                 *pointers = new unsigned char*[asset->height];
135                 for(int i = 0; i < asset->height; i++)
136                 {
137                         (*pointers)[i] = &buffer[i * asset->width * depth / 8];
138                 }
139         }
142 int FileBase::match4(char *in, char *out)
144         if(in[0] == out[0] &&
145                 in[1] == out[1] &&
146                 in[2] == out[2] &&
147                 in[3] == out[3])
148                 return 1;
149         else
150                 return 0;
153 int FileBase::search_render_strategies(ArrayList<int>* render_strategies, int render_strategy)
155         int i;
156         for(i = 0; i < render_strategies->total; i++)
157                 if(render_strategies->values[i] == render_strategy) return 1;
159         return 0;