1 #include <sstream>
2 
3 #include "ADM_default.h"
4 #include "ADM_vidMisc.h"
5 #include "SpiderMonkeyEngine.h"
6 #include "ADM_jsEditor.h"
7 
8 using namespace std;
9 
10 /**
11 \fn jsPrintTiming
12 */
jsPrintTiming(JSContext * cx,int framenumber)13 int jsPrintTiming(JSContext *cx, int framenumber)
14 {
15 	uint32_t flags;
16 	uint64_t pts, dts;
17 
18 	SpiderMonkeyEngine *engine = (SpiderMonkeyEngine*)JS_GetContextPrivate(cx);
19 	IEditor *videoBody = engine->editor();
20 
21 	if (videoBody->getVideoPtsDts(framenumber, &flags, &pts, &dts))
22 	{
23 		int64_t delta = 0;
24 		char field = 'F';
25 
26 		if (flags & AVI_BOTTOM_FIELD) field = 'B';
27 		if (flags & AVI_TOP_FIELD) field = 'T';
28 		if (pts != ADM_NO_PTS && dts != ADM_NO_PTS) delta = (int64_t)pts - (int64_t)dts;
29 
30 		stringstream stream;
31 
32 		stream << "Frame " << framenumber << " PIC: " << field << " Flags " << flags << " pts=" << pts <<
33 			" pts=" << ADM_us2plain(pts) << " dts=" << dts << " delta=" << delta / 1000LL << " ms";
34 
35 		engine->callEventHandlers(IScriptEngine::Information, NULL, -1, stream.str().c_str());
36 	}
37 	else
38 	{
39 		stringstream stream;
40 
41 		stream << "Cannot get info for frame " << framenumber;
42 
43 		engine->callEventHandlers(IScriptEngine::Information, NULL, -1, stream.str().c_str());
44 	}
45 
46 	return 0;
47 }
48 
49 /**
50 \fn jsHexDumpFrame
51 */
jsHexDumpFrame(JSContext * cx,int framenumber)52 int jsHexDumpFrame(JSContext *cx, int framenumber)
53 {
54 	ADMCompressedImage img;
55 	SpiderMonkeyEngine *engine = (SpiderMonkeyEngine*)JS_GetContextPrivate(cx);
56 	IEditor *videoBody = engine->editor();
57 
58 	img.data = new uint8_t[2000 * 2000 * 3];
59 	img.dataLength = 2000 * 2000 * 3;
60 
61 	if (!videoBody->getDirectImageForDebug(framenumber, &img))
62 	{
63 		stringstream stream;
64 
65 		stream << "Cannot get picture " << framenumber;
66 		engine->callEventHandlers(IScriptEngine::Information, NULL, -1, stream.str().c_str());
67 		delete [] img.data;
68 
69 		return false;
70 	}
71 
72 	mixDump(img.data,img.dataLength);
73 	delete [] img.data;
74 
75 	return true;
76 }
77 
78 /**
79 \fn    jsDumpSegments
80 \brief dump segment, video & all
81 */
jsDumpSegments(JSContext * cx)82 int jsDumpSegments (JSContext *cx)
83 {// begin PostProcess
84 	IEditor *videoBody = ((SpiderMonkeyEngine*)JS_GetContextPrivate(cx))->editor();
85 
86 	videoBody->dumpSegments();
87 
88 	return 0;
89 }// end PostProcess
90 
91 /**
92 \fn jsDumpRefVideos
93 */
jsDumpRefVideos(JSContext * cx)94 int jsDumpRefVideos (JSContext *cx)
95 {
96 	IEditor *videoBody = ((SpiderMonkeyEngine*)JS_GetContextPrivate(cx))->editor();
97 
98 	videoBody->dumpRefVideos();
99 
100 	return 0;
101 }
102 
103 /**
104 \fn dumpTiming
105 \brief dump segment, video & all
106 */
dumpTiming(JSContext * cx)107 JSBool dumpTiming(JSContext *cx)
108 {// begin PostProcess
109 	IEditor *videoBody = ((SpiderMonkeyEngine*)JS_GetContextPrivate(cx))->editor();
110 
111 	videoBody->dumpTiming();
112 
113 	return 0;
114 }// end PostProcess
115 
116 /**
117 \fn scriptGetVideoDuration
118 */
scriptGetVideoDuration(JSContext * cx)119 float scriptGetVideoDuration(JSContext *cx)
120 {
121 	IEditor *videoBody = ((SpiderMonkeyEngine*)JS_GetContextPrivate(cx))->editor();
122 	uint64_t d = videoBody->getVideoDuration();
123 
124 	return (float)d;
125 }
126 
127 /**
128 \fn scriptGetPts
129 */
scriptGetPts(JSContext * cx,int frameNum)130 double  scriptGetPts(JSContext *cx, int frameNum)
131 {
132 	uint32_t flags;
133 	uint64_t pts, dts;
134 	IEditor *videoBody = ((SpiderMonkeyEngine*)JS_GetContextPrivate(cx))->editor();
135 
136 	if(!videoBody->getVideoPtsDts(frameNum, &flags, &pts, &dts))
137 	{
138 		ADM_warning("Cannot get PTS for frame %" PRIu32"\n", frameNum);
139 		return -1;
140 	}
141 
142 	if(pts == ADM_NO_PTS) return -1;
143 
144 	return (double)pts;
145 }
146 
147 /**
148 \fn scriptGetDts
149 */
scriptGetDts(JSContext * cx,int frameNum)150 double  scriptGetDts(JSContext *cx, int frameNum)
151 {
152 	uint32_t flags;
153 	uint64_t pts,dts;
154 	IEditor *videoBody = ((SpiderMonkeyEngine*)JS_GetContextPrivate(cx))->editor();
155 
156 	if(!videoBody->getVideoPtsDts(frameNum, &flags, &pts, &dts))
157 	{
158 		ADM_warning("Cannot get DTS for frame %" PRIu32"\n", frameNum);
159 		return -1;
160 	}
161 
162 	if(dts == ADM_NO_PTS) return -1;
163 
164 	return (double)dts;
165 }
166