22 #include "mythprotorecorder.h" 23 #include "../private/debug.h" 24 #include "../private/os/threads/mutex.h" 25 #include "../private/builtin.h" 33 ProtoRecorder::ProtoRecorder(
int num,
const std::string& server,
unsigned port)
37 , m_liveRecording(false)
39 ProtoPlayback::Open();
42 ProtoRecorder::~ProtoRecorder()
46 ProtoPlayback::Close();
49 int ProtoRecorder::GetNum()
const 54 bool ProtoRecorder::IsPlaying()
const 59 bool ProtoRecorder::IsTunable(
const Channel& channel)
62 CardInputListPtr inputlist = GetFreeInputs();
63 for (CardInputList::const_iterator it = inputlist->begin(); it != inputlist->end(); ++it)
66 if (input->sourceId != channel.sourceId)
68 DBG(DBG_DEBUG,
"%s: skip input, source id differs (channel: %" PRIu32
", input: %" PRIu32
")\n",
69 __FUNCTION__, channel.sourceId, input->sourceId);
72 if (input->mplexId && input->mplexId != channel.mplexId)
74 DBG(DBG_DEBUG,
"%s: skip input, multiplex id differs (channel: %" PRIu32
", input: %" PRIu32
")\n",
75 __FUNCTION__, channel.mplexId, input->mplexId);
78 DBG(DBG_DEBUG,
"%s: using recorder, input is tunable: source id: %" PRIu32
", multiplex id: %" PRIu32
", channel: %" PRIu32
", input: %" PRIu32
")\n",
79 __FUNCTION__, channel.sourceId, channel.mplexId, channel.chanId, input->inputId);
85 DBG(DBG_INFO,
"%s: recorder is not tunable\n", __FUNCTION__);
90 void ProtoRecorder::DoneRecordingCallback()
92 OS::CLockGuard lock(*m_mutex);
93 m_liveRecording =
false;
94 DBG(DBG_DEBUG,
"%s: completed\n", __FUNCTION__);
97 bool ProtoRecorder::SpawnLiveTV75(
const std::string& chainid,
const std::string& channum)
102 OS::CLockGuard lock(*m_mutex);
105 std::string cmd(
"QUERY_RECORDER ");
106 int32_to_string((int32_t)m_num, buf);
108 cmd.append(PROTO_STR_SEPARATOR);
109 cmd.append(
"SPAWN_LIVETV");
110 cmd.append(PROTO_STR_SEPARATOR);
112 cmd.append(PROTO_STR_SEPARATOR).append(
"0").append(PROTO_STR_SEPARATOR);
115 DBG(DBG_DEBUG,
"%s: starting ...\n", __FUNCTION__);
117 if (!SendCommand(cmd.c_str()))
121 else if (!
ReadField(field) || !IsMessageOK(field))
126 DBG(DBG_DEBUG,
"%s: %s\n", __FUNCTION__, (m_playing ?
"succeeded" :
"failed"));
130 bool ProtoRecorder::StopLiveTV75()
135 OS::CLockGuard lock(*m_mutex);
138 std::string cmd(
"QUERY_RECORDER ");
139 int32_to_string((int32_t)m_num, buf);
141 cmd.append(PROTO_STR_SEPARATOR);
142 cmd.append(
"STOP_LIVETV");
144 if (!SendCommand(cmd.c_str()))
146 if (!
ReadField(field) || !IsMessageOK(field))
155 bool ProtoRecorder::CheckChannel75(
const std::string& channum)
160 OS::CLockGuard lock(*m_mutex);
163 std::string cmd(
"QUERY_RECORDER ");
164 int32_to_string((int32_t)m_num, buf);
166 cmd.append(PROTO_STR_SEPARATOR);
167 cmd.append(
"CHECK_CHANNEL");
168 cmd.append(PROTO_STR_SEPARATOR);
171 if (!SendCommand(cmd.c_str()))
175 DBG(DBG_DEBUG,
"%s: %s\n", __FUNCTION__, field.c_str());
182 ProgramPtr ProtoRecorder::GetCurrentRecording75()
187 OS::CLockGuard lock(*m_mutex);
190 std::string cmd(
"QUERY_RECORDER ");
191 int32_to_string((int32_t)m_num, buf);
193 cmd.append(PROTO_STR_SEPARATOR);
194 cmd.append(
"GET_CURRENT_RECORDING");
196 if (!SendCommand(cmd.c_str()))
199 if (!(program = RcvProgramInfo()))
204 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
209 int64_t ProtoRecorder::GetFilePosition75()
215 OS::CLockGuard lock(*m_mutex);
216 if (!IsOpen() || !IsPlaying())
218 std::string cmd(
"QUERY_RECORDER ");
219 int32_to_string((int32_t)m_num, buf);
221 cmd.append(PROTO_STR_SEPARATOR);
222 cmd.append(
"GET_FILE_POSITION");
224 if (!SendCommand(cmd.c_str()))
227 if (!
ReadField(field) || string_to_int64(field.c_str(), &pos))
238 CardInputListPtr ProtoRecorder::GetFreeInputs75()
240 CardInputListPtr list = CardInputListPtr(
new CardInputList());
244 OS::CLockGuard lock(*m_mutex);
247 std::string cmd(
"QUERY_RECORDER ");
248 int32_to_string((int32_t)m_num, buf);
250 cmd.append(PROTO_STR_SEPARATOR);
251 cmd.append(
"GET_FREE_INPUTS");
253 if (!SendCommand(cmd.c_str()))
256 while (m_msgConsumed < m_msgLength)
261 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
263 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
265 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
267 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
269 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
271 list->push_back(input);
277 CardInputListPtr ProtoRecorder::GetFreeInputs79()
279 CardInputListPtr list = CardInputListPtr(
new CardInputList());
283 OS::CLockGuard lock(*m_mutex);
286 std::string cmd(
"QUERY_RECORDER ");
287 int32_to_string((int32_t)m_num, buf);
289 cmd.append(PROTO_STR_SEPARATOR);
290 cmd.append(
"GET_FREE_INPUTS");
292 if (!SendCommand(cmd.c_str()))
295 while (m_msgConsumed < m_msgLength)
300 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
302 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
304 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
306 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
308 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
318 list->push_back(input);
324 CardInputListPtr ProtoRecorder::GetFreeInputs81()
326 CardInputListPtr list = CardInputListPtr(
new CardInputList());
330 OS::CLockGuard lock(*m_mutex);
333 std::string cmd(
"QUERY_RECORDER ");
334 int32_to_string((int32_t)m_num, buf);
336 cmd.append(PROTO_STR_SEPARATOR);
337 cmd.append(
"GET_FREE_INPUTS");
339 if (!SendCommand(cmd.c_str()))
342 while (m_msgConsumed < m_msgLength)
347 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
349 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
351 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
353 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
355 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
367 list->push_back(input);
373 CardInputListPtr ProtoRecorder::GetFreeInputs87()
375 CardInputListPtr list = CardInputListPtr(
new CardInputList());
378 OS::CLockGuard lock(*m_mutex);
381 std::string cmd(
"GET_FREE_INPUT_INFO 0");
383 if (!SendCommand(cmd.c_str()))
386 while (m_msgConsumed < m_msgLength)
391 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
393 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
395 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
397 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
399 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
411 if (input->cardId == static_cast<unsigned>(m_num))
412 list->push_back(input);
418 CardInputListPtr ProtoRecorder::GetFreeInputs89()
420 CardInputListPtr list = CardInputListPtr(
new CardInputList());
423 OS::CLockGuard lock(*m_mutex);
426 std::string cmd(
"GET_FREE_INPUT_INFO 0");
428 if (!SendCommand(cmd.c_str()))
431 while (m_msgConsumed < m_msgLength)
436 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
438 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
440 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->cardId)))
442 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
444 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
458 if (input->cardId == static_cast<unsigned>(m_num))
459 list->push_back(input);
465 CardInputListPtr ProtoRecorder::GetFreeInputs90()
467 CardInputListPtr list = CardInputListPtr(
new CardInputList());
470 OS::CLockGuard lock(*m_mutex);
473 std::string cmd(
"GET_FREE_INPUT_INFO 0");
475 if (!SendCommand(cmd.c_str()))
478 while (m_msgConsumed < m_msgLength)
483 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
485 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
487 input->cardId = input->inputId;
490 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
492 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
506 if (input->cardId == static_cast<unsigned>(m_num))
507 list->push_back(input);
513 CardInputListPtr ProtoRecorder::GetFreeInputs91()
515 CardInputListPtr list = CardInputListPtr(
new CardInputList());
518 OS::CLockGuard lock(*m_mutex);
521 std::string cmd(
"GET_FREE_INPUT_INFO 0");
523 if (!SendCommand(cmd.c_str()))
526 while (m_msgConsumed < m_msgLength)
531 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->sourceId)))
533 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->inputId)))
535 input->cardId = input->inputId;
536 if (!
ReadField(field) || string_to_uint32(field.c_str(), &(input->mplexId)))
538 if (!
ReadField(field) || string_to_uint8(field.c_str(), &(input->liveTVOrder)))
550 if (input->cardId == static_cast<unsigned>(m_num))
551 list->push_back(input);
557 bool ProtoRecorder::IsLiveRecording()
559 OS::CLockGuard lock(*m_mutex);
560 return m_liveRecording;
563 bool ProtoRecorder::SetLiveRecording75(
bool keep)
568 OS::CLockGuard lock(*m_mutex);
571 std::string cmd(
"QUERY_RECORDER ");
572 int32_to_string((int32_t)m_num, buf);
574 cmd.append(PROTO_STR_SEPARATOR);
575 cmd.append(
"SET_LIVE_RECORDING").append(PROTO_STR_SEPARATOR);
581 if (!SendCommand(cmd.c_str()))
584 if (!
ReadField(field) || !IsMessageOK(field))
586 DBG(DBG_DEBUG,
"%s: succeeded (%d)\n", __FUNCTION__, keep);
589 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
594 bool ProtoRecorder::FinishRecording75()
599 OS::CLockGuard lock(*m_mutex);
602 std::string cmd(
"QUERY_RECORDER ");
603 int32_to_string((int32_t)m_num, buf);
605 cmd.append(PROTO_STR_SEPARATOR);
606 cmd.append(
"FINISH_RECORDING");
608 if (!SendCommand(cmd.c_str()))
611 if (!
ReadField(field) || !IsMessageOK(field))
613 DBG(DBG_DEBUG,
"%s: succeeded\n", __FUNCTION__);
616 DBG(DBG_ERROR,
"%s: failed\n", __FUNCTION__);
bool ReadField(std::string &field)
This is the main namespace that encloses all public classes.