86
94
throw _Exception(_("Transcoding of file ") + location +
87
95
"requested but no profile given");
89
isURL = (IS_CDS_ITEM_INTERNAL_URL(objectType) ||
90
IS_CDS_ITEM_EXTERNAL_URL(objectType));
97
isURL = (IS_CDS_ITEM_INTERNAL_URL(obj->getObjectType()) ||
98
IS_CDS_ITEM_EXTERNAL_URL(obj->getObjectType()));
92
100
String mimeType = profile->getTargetMimeType();
102
if (IS_CDS_ITEM(obj->getObjectType()))
104
Ref<CdsItem> it = RefCast(obj, CdsItem);
105
Ref<Dictionary> mappings = ConfigManager::getInstance()->getDictionaryOption(
106
CFG_IMPORT_MAPPINGS_MIMETYPE_TO_CONTENTTYPE_LIST);
108
if (mappings->get(mimeType) == CONTENT_TYPE_PCM)
110
String freq = it->getResource(0)->getAttribute(MetadataHandler::getResAttrName(R_SAMPLEFREQUENCY));
111
String nrch = it->getResource(0)->getAttribute(MetadataHandler::getResAttrName(R_NRAUDIOCHANNELS));
114
mimeType = mimeType + _(";rate=") + freq;
116
mimeType = mimeType + _(";channels=") + nrch;
94
120
info->content_type = ixmlCloneDOMString(mimeType.c_str());
96
122
info->file_length = UNKNOWN_CONTENT_LENGTH;
123
info->force_chunked = (int)profile->getChunked();
98
125
Ref<ConfigManager> cfg = ConfigManager::getInstance();
100
String fifo_name = tempName(cfg->getOption(CFG_SERVER_TMPDIR),
127
String fifo_name = normalizePath(tempName(cfg->getOption(CFG_SERVER_TMPDIR),
102
129
String arguments;
105
132
Ref<Array<StringBase> > arglist;
106
133
Ref<Array<ProcListItem> > proc_list = nil;
108
if (isURL && (!profile->acceptURL()))
136
service_type_t service = OS_None;
137
if (obj->getFlag(OBJECT_FLAG_ONLINE_SERVICE))
139
service = (service_type_t)(obj->getAuxData(_(ONLINE_SERVICE_AUX_ID)).toInt());
142
if (service == OS_SopCast)
144
Ref<Array<StringBase> > sop_args;
145
int p1 = find_local_port(45000,65500);
146
int p2 = find_local_port(45000,65500);
147
sop_args = parseCommandLine(location + " " + String::from(p1) + " " +
148
String::from(p2), nil, nil);
149
Ref<ProcessExecutor> spsc(new ProcessExecutor(_("sp-sc-auth"),
151
proc_list = Ref<Array<ProcListItem> >(new Array<ProcListItem>(1));
152
Ref<ProcListItem> pr_item(new ProcListItem(RefCast(spsc, Executor)));
153
proc_list->append(pr_item);
154
location = _("http://localhost:") + String::from(p2) + "/tv.asf";
155
#warning check if socket is ready
158
#warning check if we can use "accept url" with sopcast
162
if (isURL && (!profile->acceptURL()))
111
String url = location;
165
String url = location;
166
strcpy(fifo_template, "mt_transcode_XXXXXX");
167
location = normalizePath(tempName(cfg->getOption(CFG_SERVER_TMPDIR), fifo_template));
168
log_debug("creating reader fifo: %s\n", location.c_str());
169
if (mkfifo(location.c_str(), O_RDWR) == -1)
171
log_error("Failed to create fifo for the remote content "
172
"reading thread: %s\n", strerror(errno));
173
throw _Exception(_("Could not create reader fifo!\n"));
178
chmod(location.c_str(), S_IWUSR | S_IRUSR);
180
Ref<IOHandler> c_ioh(new CurlIOHandler(url, NULL,
181
cfg->getIntOption(CFG_EXTERNAL_TRANSCODING_CURL_BUFFER_SIZE),
182
cfg->getIntOption(CFG_EXTERNAL_TRANSCODING_CURL_FILL_SIZE)));
184
Ref<IOHandler> p_ioh(new ProcessIOHandler(location, nil));
185
Ref<Executor> ch(new IOHandlerChainer(c_ioh, p_ioh, 16384));
186
proc_list = Ref<Array<ProcListItem> >(new Array<ProcListItem>(1));
187
Ref<ProcListItem> pr_item(new ProcListItem(ch));
188
proc_list->append(pr_item);
192
unlink(location.c_str());
196
throw _Exception(_("MediaTomb was compiled without libcurl support,"
197
"data proxying is not available"));
205
#ifdef HAVE_LIBDVDNAV
206
if (obj->getFlag(OBJECT_FLAG_DVD_IMAGE))
112
208
strcpy(fifo_template, "mt_transcode_XXXXXX");
113
location = tempName(cfg->getOption(CFG_SERVER_TMPDIR), fifo_template);
209
location = normalizePath(tempName(cfg->getOption(CFG_SERVER_TMPDIR), fifo_template));
114
210
log_debug("creating reader fifo: %s\n", location.c_str());
115
211
if (mkfifo(location.c_str(), O_RDWR) == -1)
117
log_error("Failed to create fifo for the remote content reading thread: %s\n", strerror(errno));
213
log_error("Failed to create fifo for the DVD image "
214
"reading thread: %s\n", strerror(errno));
118
215
throw _Exception(_("Could not create reader fifo!\n"));
221
String tmp = obj->getResource(0)->getParameter(DVDHandler::renderKey(DVD_Title));
223
throw _Exception(_("DVD Image requested but title parameter is missing!"));
224
int title = tmp.toInt();
226
throw _Exception(_("DVD Image - requested invalid title!"));
228
tmp = obj->getResource(0)->getParameter(DVDHandler::renderKey(DVD_Chapter));
230
throw _Exception(_("DVD Image requested but chapter parameter is missing!"));
231
int chapter = tmp.toInt();
233
throw _Exception(_("DVD Image - requested invalid chapter!"));
235
// actually we are retrieving the audio stream id here
236
tmp = obj->getResource(0)->getParameter(DVDHandler::renderKey(DVD_AudioStreamID));
238
throw _Exception(_("DVD Image requested but audio track parameter is missing!"));
239
int audio_track = tmp.toInt();
241
throw _Exception(_("DVD Image - requested invalid audio stream ID!"));
123
243
chmod(location.c_str(), S_IWUSR | S_IRUSR);
125
Ref<IOHandler> c_ioh(new CurlIOHandler(url, NULL,
126
cfg->getIntOption(CFG_EXTERNAL_TRANSCODING_CURL_BUFFER_SIZE),
127
cfg->getIntOption(CFG_EXTERNAL_TRANSCODING_CURL_FILL_SIZE)));
245
Ref<IOHandler> dvd_ioh(new DVDIOHandler(obj->getLocation(), title, chapter, audio_track));
248
if (pipe(from_dvd_fd) == -1)
249
throw _Exception(_("Failed to create DVD input pipe!"));
251
int from_remux_fd[2];
252
if (pipe(from_remux_fd) == -1)
254
close(from_dvd_fd[0]);
255
close(from_dvd_fd[1]);
256
throw _Exception(_("Failed to create remux output pipe!"));
259
Ref<IOHandler> fd_writer(new FDIOHandler(from_dvd_fd[1]));
260
Ref<Executor> from_dvd(new IOHandlerChainer(dvd_ioh,
263
Ref<IOHandler> fd_reader(new FDIOHandler(from_remux_fd[0]));
265
Ref<MPEGRemuxProcessor> remux(new MPEGRemuxProcessor(from_dvd_fd[0],
267
(unsigned char)audio_track));
269
RefCast(fd_reader, FDIOHandler)->addReference(RefCast(remux, Object));
270
RefCast(fd_reader, FDIOHandler)->addReference(RefCast(from_dvd, Object));
271
RefCast(fd_reader, FDIOHandler)->addReference(RefCast(fd_writer, Object));
272
RefCast(fd_reader, FDIOHandler)->closeOther(fd_writer);
129
275
Ref<IOHandler> p_ioh(new ProcessIOHandler(location, nil));
130
Ref<Executor> ch(new IOHandlerChainer(c_ioh, p_ioh, 16384));
131
proc_list = Ref<Array<ProcListItem> >(new Array<ProcListItem>(1));
276
Ref<Executor> ch(new IOHandlerChainer(fd_reader, p_ioh, 16384));
277
proc_list = Ref<Array<ProcListItem> >(new Array<ProcListItem>(2));
132
278
Ref<ProcListItem> pr_item(new ProcListItem(ch));
133
279
proc_list->append(pr_item);
280
Ref<ProcListItem> pr2_item(new ProcListItem(from_dvd));
281
proc_list->append(pr2_item);
135
283
catch (Exception ex)
137
285
unlink(location.c_str());
141
throw _Exception(_("MediaTomb was compiled without libcurl support,"
142
"data proxying is not available"));
148
292
if (profile->getCommand().startsWith(_(_DIR_SEPARATOR)))