r827: Fix a crash when no audio output device can be opened.
[cinelerra_cv.git] / cinelerra / filecr2.C
blob24cbff12bc5cf2fa0e20c2c2d2e5ada658fa0e71
1 #include "asset.h"
2 #include "colormodels.h"
3 #include "filecr2.h"
4 #include "mutex.h"
5 #include <string.h>
6 #include <unistd.h>
8 // Only allow one instance of the decoder to run simultaneously.
9 static Mutex cr2_mutex;
12 FileCR2::FileCR2(Asset *asset, File *file)
13  : FileBase(asset, file)
15         reset();
18 FileCR2::~FileCR2()
20         close_file();
24 void FileCR2::reset()
28 int FileCR2::check_sig(Asset *asset)
30         cr2_mutex.lock("FileCR2::check_sig");
31         char string[BCTEXTLEN];
32         int argc = 3;
34         strcpy(string, asset->path);
36         char *argv[4];
37         argv[0] = "dcraw";
38         argv[1] = "-i";
39         argv[2] = string;
40         argv[3] = 0;
42         int result = dcraw_main(argc, argv);
44         cr2_mutex.unlock();
46         return !result;
49 int FileCR2::open_file(int rd, int wr)
51         cr2_mutex.lock("FileCR2::check_sig");
53         int argc = 3;
54         char *argv[3] = 
55         {
56                 "dcraw",
57                 "-i",
58                 asset->path
59         };
61         int result = dcraw_main(argc, argv);
62         if(!result) format_to_asset();
64         cr2_mutex.unlock();
65         return result;
69 int FileCR2::close_file()
71         return 0;
74 void FileCR2::format_to_asset()
76         asset->video_data = 1;
77         asset->layers = 1;
78         sscanf(dcraw_info, "%d %d", &asset->width, &asset->height);
79         if(!asset->frame_rate) asset->frame_rate = 1;
80         asset->video_length = -1;
84 int FileCR2::read_frame(VFrame *frame)
86         cr2_mutex.lock("FileCR2::check_sig");
87         if(frame->get_color_model() == BC_RGBA_FLOAT)
88                 dcraw_alpha = 1;
89         else
90                 dcraw_alpha = 0;
93 // output to stdout
94         int argc = 3;
95         char *argv[3] = 
96         {
97                 "dcraw",
98                 "-c",
99                 asset->path
100         };
101         dcraw_data = (float**)frame->get_rows();
103         int result = dcraw_main(argc, argv);
105         cr2_mutex.unlock();
106         return 0;
109 int FileCR2::colormodel_supported(int colormodel)
111         if(colormodel == BC_RGB_FLOAT ||
112                 colormodel == BC_RGBA_FLOAT)
113                 return colormodel;
114         return BC_RGB_FLOAT;