1 #include "SpiderMonkeyScriptWriter.h"
2 #include "ADM_coreVideoEncoderInternal.h"
3 #include "ADM_muxerInternal.h"
4 #include "ADM_audiocodec/ADM_audiocodec.h"
5 #include "ADM_editor/include/ADM_edEditableAudioTrack.h"
6 
SpiderMonkeyScriptWriter()7 SpiderMonkeyScriptWriter::SpiderMonkeyScriptWriter()
8 {
9 	this->_stream = NULL;
10 }
11 
12 
setAudioPoolLanguage(int trackIndex,const char * lang)13 void SpiderMonkeyScriptWriter::setAudioPoolLanguage(int trackIndex, const char *lang) // ! from pool, not activeAudioTrack
14 {
15 
16 }
addExternalAudioTrack(int trackIndex,const char * file)17 void SpiderMonkeyScriptWriter::addExternalAudioTrack(int trackIndex,const char *file)
18 {
19 
20 }
21 
addAudioOutput(int trackIndex,ADM_audioEncoder * encoder,EditableAudioTrack * track)22 void SpiderMonkeyScriptWriter::addAudioOutput(int trackIndex, ADM_audioEncoder *encoder, EditableAudioTrack* track)
23 {
24     *(this->_stream) << "adm.audioCodec(" << trackIndex << ", \"" << encoder->codecName << "\"";
25     this->dumpConfCouple(track->encoderConf);
26     *(this->_stream) << ");" << std::endl;
27 }
28 
addSegment(uint32_t videoIndex,uint64_t startTime,uint64_t duration)29 void SpiderMonkeyScriptWriter::addSegment(uint32_t videoIndex, uint64_t startTime, uint64_t duration)
30 {
31     *(this->_stream) << "adm.addSegment(" << videoIndex << ", " << startTime << ", " << duration << ");" << std::endl;
32 }
33 
addVideoFilter(ADM_vf_plugin * plugin,ADM_VideoFilterElement * element)34 void SpiderMonkeyScriptWriter::addVideoFilter(ADM_vf_plugin *plugin, ADM_VideoFilterElement *element)
35 {
36     *(this->_stream) << "adm.addVideoFilter(\"" << plugin->getInternalName() << "\"";
37 
38 	CONFcouple *configuration;
39 
40 	element->instance->getCoupledConf(&configuration);
41     this->dumpConfCouple(configuration);
42 	delete configuration;
43 
44     *(this->_stream) << ");" << std::endl;
45 }
46 
appendVideo(const char * path)47 void SpiderMonkeyScriptWriter::appendVideo(const char* path)
48 {
49     *(this->_stream) << "adm.appendVideo(\"" << path << "\");" << std::endl;
50 }
setAudioDrc(int trackIndex,bool active)51 void SpiderMonkeyScriptWriter::setAudioDrc(int trackIndex, bool active)
52 {
53 
54 }
setAudioShift(int trackIndex,bool active,int32_t value)55 void SpiderMonkeyScriptWriter::setAudioShift(int trackIndex, bool active,int32_t value)
56 {
57 
58 }void SpiderMonkeyScriptWriter::clearAudioTracks()
59 {
60 
61 }
62 
clearSegments()63 void SpiderMonkeyScriptWriter::clearSegments()
64 {
65     *(this->_stream) << "adm.clearSegments();" << std::endl;
66 }
67 
closeVideo()68 void SpiderMonkeyScriptWriter::closeVideo()
69 {
70 
71 }
72 
connectStream(std::iostream & stream)73 void SpiderMonkeyScriptWriter::connectStream(std::iostream& stream)
74 {
75     this->_stream = &stream;
76 
77     *(this->_stream) << "//AD  <- Needed to identify //" << std::endl;
78     *(this->_stream) << "//--automatically built--\n" << std::endl << std::endl;
79 }
80 
disconnectStream()81 void SpiderMonkeyScriptWriter::disconnectStream()
82 {
83     this->_stream = NULL;
84 }
85 
loadVideo(const char * path)86 void SpiderMonkeyScriptWriter::loadVideo(const char* path)
87 {
88     *(this->_stream) << "adm.loadVideo(\"" << path << "\");" << std::endl;
89 }
90 
setAudioGain(int trackIndex,ADM_GAINMode gainMode,uint32_t gainValue)91 void SpiderMonkeyScriptWriter::setAudioGain(int trackIndex, ADM_GAINMode gainMode, uint32_t gainValue)
92 {
93 
94 }
95 
setAudioMixer(int trackIndex,CHANNEL_CONF mixer)96 void SpiderMonkeyScriptWriter::setAudioMixer(int trackIndex, CHANNEL_CONF mixer)
97 {
98     const char *mixerString = NULL;
99 
100     for (unsigned int i = 0; i < NB_MIXER_DESC; i++)
101     {
102         if (mixer == mixerStringDescriptor[i].conf)
103         {
104             mixerString = mixerStringDescriptor[i].desc;
105         }
106     }
107 
108     *(this->_stream) << "adm.audioMuxer(" << trackIndex << ", \"" << mixerString << "\");" << std::endl;
109 }
110 
setAudioResample(int trackIndex,uint32_t resample)111 void SpiderMonkeyScriptWriter::setAudioResample(int trackIndex, uint32_t resample)
112 {
113 
114 }
115 
setMarkers(uint64_t markerA,uint64_t markerB)116 void SpiderMonkeyScriptWriter::setMarkers(uint64_t markerA, uint64_t markerB)
117 {
118     *(this->_stream) << "adm.markerA = " << markerA << ";" << std::endl;
119     *(this->_stream) << "adm.markerB = " << markerB << ";" << std::endl;
120 }
121 
setMuxer(ADM_dynMuxer * muxer)122 void SpiderMonkeyScriptWriter::setMuxer(ADM_dynMuxer *muxer)
123 {
124 	CONFcouple *configuration;
125 
126 	muxer->getConfiguration(&configuration);
127 
128 	*(this->_stream) << "adm.setContainer(\"" << muxer->name << "\"";
129     this->dumpConfCouple(configuration);
130     *(this->_stream) << ");" << std::endl;
131 
132 	delete configuration;
133 }
134 
setPostProcessing(uint32_t type,uint32_t strength,uint32_t swapUv)135 void SpiderMonkeyScriptWriter::setPostProcessing(uint32_t type, uint32_t strength, uint32_t swapUv)
136 {
137     *(this->_stream) << "adm.setPostProc(" << type << ", " << strength << ", " << swapUv << ");" << std::endl;
138 }
139 
setVideoEncoder(ADM_videoEncoder6 * videoEncoder)140 void SpiderMonkeyScriptWriter::setVideoEncoder(ADM_videoEncoder6* videoEncoder)
141 {
142 	CONFcouple *configuration = NULL;
143 
144 	if (videoEncoder->desc->getConfigurationData)
145 	{
146 		videoEncoder->desc->getConfigurationData(&configuration);
147 	}
148 
149     *(this->_stream) << "adm.videoCodec(\"" << videoEncoder->desc->encoderName << "\"";
150     this->dumpConfCouple(configuration);
151 	*(this->_stream) << ");" << std::endl;
152 
153 	delete configuration;
154 }
155 
stretchAudio(int trackIndex,FILMCONV fps)156 void SpiderMonkeyScriptWriter::stretchAudio(int trackIndex, FILMCONV fps)
157 {
158 
159 }
160 
dumpConfCouple(CONFcouple * c)161 void SpiderMonkeyScriptWriter::dumpConfCouple(CONFcouple *c)
162 {
163     if (!c)
164     {
165         return;
166     }
167 
168     int count = 0;
169 
170     for (unsigned int j = 0; j < c->getSize(); j++)
171     {
172         char *name, *value;
173 
174         c->getInternalName(j, &name, &value);
175         *(this->_stream) << ", \"" << name << "=" << value << "\"";
176 
177         // tinyPy does not like line > 1024 chars
178         if (count >= 20)
179         {
180             *(this->_stream) << std::endl;
181             count = 0;
182         }
183 
184         count++;
185     }
186 }
187