1 #include "ADM_inttype.h"
2 #include "ADM_confCouple.h"
3 #include "ADM_jsAvidemux.h"
4 #include "ADM_jsUtils.h"
5 #include "SpiderMonkeyEngine.h"
6
7 using namespace std;
8
9 #define ENGINE(cx) ((SpiderMonkeyEngine*)JS_GetContextPrivate(cx))
10 #define EDITOR(cx) ENGINE(cx)->editor()
11
jsVideoCodec(const char * a,const char ** b)12 int jsVideoCodec(const char *a,const char **b) {return 0;}
13
jsAdmvideoCodec(JSContext * cx,JSObject * obj,uintN argc,jsval * argv,jsval * rval)14 JSBool jsAdmvideoCodec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
15 {// begin Codec
16 *rval = BOOLEAN_TO_JSVAL(false);
17
18 if(argc < 1)
19 return JS_FALSE;
20
21 if(!JSVAL_IS_STRING(argv[0]))
22 {
23 ENGINE(cx)->callEventHandlers(
24 IScriptEngine::Information, NULL, -1, "Cannot set codec, first parameter is not a string");
25
26 return JS_FALSE;
27 }
28
29 char *codec=JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
30 CONFcouple *c;
31 jsArgToConfCouple(argc-1,&c,argv+1);
32 *rval = BOOLEAN_TO_JSVAL(EDITOR(cx)->setVideoCodec(codec, c));
33
34 return JS_TRUE;
35 }// end Codec
36
jsVideoFilter(const char * a,const char ** b)37 int jsVideoFilter(const char *a,const char **b) {return 0;}
38
jsAdmaddVideoFilter(JSContext * cx,JSObject * obj,uintN argc,jsval * argv,jsval * rval)39 JSBool jsAdmaddVideoFilter(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
40 {// begin Codec
41 uint32_t filterTag;
42
43 // default return value
44 *rval = BOOLEAN_TO_JSVAL(false);
45
46 if(argc == 0)
47 return JS_FALSE;
48
49 char *filterName=JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
50 CONFcouple *c=NULL;
51
52 if(argc)
53 jsArgToConfCouple(argc-1,&c,argv+1);
54
55 bool r = EDITOR(cx)->addVideoFilter(filterName, c);
56
57 *rval=BOOLEAN_TO_JSVAL( r);
58 return JS_TRUE;
59 }// end Codec
60
jsAudioCodec(const char * a,const char ** b)61 int jsAudioCodec(const char *a,const char **b) {return 0;}
62
jsAdmaudioCodec(JSContext * cx,JSObject * obj,uintN argc,jsval * argv,jsval * rval)63 JSBool jsAdmaudioCodec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
64 {
65 // default return value
66 *rval = BOOLEAN_TO_JSVAL(false);
67
68 if (argc < 2)
69 return JS_FALSE;
70
71 if (!JSVAL_IS_STRING(argv[1]) || !JSVAL_IS_INT(argv[0]))
72 return JS_FALSE;
73
74 for (int i = 2; i < argc; i++)
75 if (JSVAL_IS_STRING(argv[i]) == false)
76 return JS_FALSE;
77
78 // Get Codec...
79 int dex=JSVAL_TO_INT(argv[0]);
80 char *name = JS_GetStringBytes(JSVAL_TO_STRING(argv[1]));
81
82 // Construct couples
83 CONFcouple *c = NULL;
84
85 if (argc > 2)
86 {
87 int nb = argc - 2;
88 jsArgToConfCouple(nb, &c, argv + 2);
89 }
90
91 *rval = BOOLEAN_TO_JSVAL(EDITOR(cx)->setAudioCodec(dex,name, c));
92
93 return JS_TRUE;
94 }
95
jsSetContainer(const char * a,const char ** b)96 int jsSetContainer(const char *a,const char **b) {return 0;}
97
jsAdmsetContainer(JSContext * cx,JSObject * obj,uintN argc,jsval * argv,jsval * rval)98 JSBool jsAdmsetContainer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
99 {// begin Codec
100 // default return value
101 *rval = BOOLEAN_TO_JSVAL(false);
102
103 if (argc < 1)
104 {
105 ENGINE(cx)->callEventHandlers(
106 IScriptEngine::Information, NULL, -1, "setContainer needs at least one arg");
107
108 return JS_FALSE;
109 }
110
111 if (JSVAL_IS_STRING(argv[0]) == false)
112 {
113 ENGINE(cx)->callEventHandlers(
114 IScriptEngine::Information, NULL, -1, "setContainer needs at string arg");
115
116 return JS_FALSE;
117 }
118
119 char *str = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
120
121 ENGINE(cx)->callEventHandlers(
122 IScriptEngine::Information, NULL, -1, (string("Selecting container: ") + string(str)).c_str());
123
124 CONFcouple *c;
125 jsArgToConfCouple(argc - 1, &c, argv + 1);
126
127 *rval = BOOLEAN_TO_JSVAL(EDITOR(cx)->setContainer(str, c));
128
129 return JS_TRUE;
130 }
131
jsClearVideoFilters(JSContext * cx)132 void jsClearVideoFilters(JSContext *cx)
133 {
134 EDITOR(cx)->clearFilters();
135 }
136
jsAudioMixer(JSContext * cx,int dex,const char * s)137 int jsAudioMixer(JSContext *cx, int dex,const char *s)
138 {
139 return EDITOR(cx)->setAudioMixer(dex,s);
140 }
141
jsAudioReset(JSContext * cx,int dex)142 void jsAudioReset(JSContext *cx,int dex)
143 {
144 EDITOR(cx)->resetAudioFilter(dex);
145 }
146
jsGetVideoCodec(JSContext * cx)147 char *jsGetVideoCodec(JSContext *cx)
148 {
149 return EDITOR(cx)->getVideoCodec();
150 }
151
jsGetFps1000(JSContext * cx)152 int jsGetFps1000(JSContext *cx)
153 {
154 aviInfo info;
155 EDITOR(cx)->getVideoInfo(&info);
156
157 return info.fps1000;
158 }
159
jsGetWidth(JSContext * cx)160 int jsGetWidth(JSContext *cx)
161 {
162 aviInfo info;
163 EDITOR(cx)->getVideoInfo(&info);
164
165 return info.width;
166 }
167
jsGetHeight(JSContext * cx)168 int jsGetHeight(JSContext *cx)
169 {
170 aviInfo info;
171 EDITOR(cx)->getVideoInfo(&info);
172
173 return info.height;
174 }
175
jsAddSegment(JSContext * cx,int ref,double start,double duration)176 int jsAddSegment(JSContext *cx, int ref, double start, double duration)
177 {
178 printf("1\n");
179 if (EDITOR(cx)->addSegment(ref, (uint64_t)start, (uint64_t)duration))
180 {
181 printf("2\n");
182 if (EDITOR(cx)->getNbSegment() == 1) // We just added our first seg...
183 {
184 printf("3\n");
185 ENGINE(cx)->callEventHandlers(
186 IScriptEngine::Information, NULL, -1, "First segment, refreshing screen");
187 EDITOR(cx)->rewind();
188 printf("4\n");
189 }
190
191 return 1;
192 }
193
194 return 0;
195 }
196
jsClearSegments(JSContext * cx)197 void jsClearSegments(JSContext *cx)
198 {
199 EDITOR(cx)->clearSegment();
200 }
201
jsSetPostProc(JSContext * cx,int a,int b,int c)202 int jsSetPostProc(JSContext *cx, int a, int b, int c)
203 {
204 return EDITOR(cx)->setPostProc(a, b, c);
205 }
206
jsAppendVideo(JSContext * cx,const char * s)207 int jsAppendVideo(JSContext *cx, const char *s)
208 {
209 return EDITOR(cx)->appendFile(s);
210 }
211
jsGetMarkerA(JSContext * cx)212 double jsGetMarkerA(JSContext *cx)
213 {
214 return (double)EDITOR(cx)->getMarkerAPts();
215 }
216
jsGetMarkerB(JSContext * cx)217 double jsGetMarkerB(JSContext *cx)
218 {
219 return (double)EDITOR(cx)->getMarkerBPts();
220 }
221
jsSetMarkerA(JSContext * cx,double a)222 void jsSetMarkerA(JSContext *cx, double a)
223 {
224 EDITOR(cx)->setMarkerAPts((uint64_t)a);
225 }
226
jsSetMarkerB(JSContext * cx,double b)227 void jsSetMarkerB(JSContext *cx, double b)
228 {
229 EDITOR(cx)->setMarkerBPts((uint64_t)b);
230 }
231
jsGetResample(JSContext * cx,int dex)232 uint32_t jsGetResample(JSContext *cx,int dex)
233 {
234 return EDITOR(cx)->getAudioResample(dex);
235 }
236
jsSetResample(JSContext * cx,int dex,uint32_t fq)237 void jsSetResample(JSContext *cx, int dex,uint32_t fq)
238 {
239 return EDITOR(cx)->setAudioResample(dex,fq);
240 }
241
jsLoadVideo(JSContext * cx,const char * s)242 int jsLoadVideo(JSContext *cx, const char *s)
243 {
244 return EDITOR(cx)->openFile(s);
245 }
246