32 "MPEG-2 PS",
"MPEG-2 TS",
"MPEG-1 VCD",
"PES AV",
33 "",
"PES V",
"",
"PES A",
35 "SVCD",
"DVD-Special 1",
"DVD-Special 2"
40 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
45 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384
50 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320
53 #define LOC QString("V4L2SH[%1](%2): ").arg(m_inputId).arg(m_device)
60 int audioinput,
int inputid)
64 const QString& devkey = devname;
66 QMap<QString,V4L2encStreamHandler*>::iterator it =
s_handlers.find(devkey);
75 LOG(VB_RECORD, LOG_INFO,
76 QString(
"V4L2SH[%1]: Creating new stream handler for %2")
77 .arg(inputid).arg(devname));
83 LOG(VB_RECORD, LOG_INFO,
84 QString(
"V4L2SH[%1]: Using existing stream handler for %2")
85 .arg(inputid).arg(devkey) + QString(
" (%1 in use)").arg(rcount));
101 LOG(VB_RECORD, LOG_INFO, QString(
"V4L2SH[%1]: Return '%2' in use %3")
102 .arg(inputid).arg(devname).arg(*rit));
111 QMap<QString, V4L2encStreamHandler*>::iterator it =
115 LOG(VB_RECORD, LOG_INFO, QString(
"V4L2SH[%1]: Closing handler for %2")
116 .arg(inputid).arg(devname));
122 LOG(VB_GENERAL, LOG_ERR,
123 QString(
"V4L2SH[%1]: Error: Couldn't find handler for %2")
124 .arg(inputid).arg(devname));
138 return !failed && !failing;
142 int audio_input,
int inputid)
144 , m_audioInput(audio_input)
150 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"-- Failed to open %1: ")
155 LOG(VB_RECORD, LOG_INFO,
LOC + QString(
"'%1' open").arg(
m_device));
168 LOG(VB_RECORD, LOG_INFO,
LOC +
"run() -- begin");
172 LOG(VB_GENERAL, LOG_WARNING,
LOC +
173 "Starting stream handler, but v4l2 is not open!");
176 LOG(VB_GENERAL, LOG_ERR,
LOC +
177 QString(
"run() -- Failed to open %1: ")
190 bool good_data =
false;
203 LOG(VB_RECORD, LOG_INFO,
LOC +
"Waiting for stream start.");
214 int len =
m_drb->
Read(
reinterpret_cast<unsigned char *
>(pkt_buf),
218 LOG(VB_GENERAL, LOG_ERR,
LOC +
"run() -- Device error detected");
238 LOG(VB_GENERAL, LOG_ERR,
LOC +
"run() -- Device EOF detected");
243 #if 0 // For this to work, the data needs to be propagated back up to
251 QMutexLocker locker(&statisticsLock);
254 for (Irec = m_rec_gaps.begin();
255 Irec != m_rec_caps.end(); ++Irec)
258 (gap_start, gap_end));
260 LOG(VB_RECORD, LOG_DEBUG,
261 LOC + QString(
"Inserted gap %1 dur %2")
262 .arg(recordingGaps.back().toString())
263 .arg(gap_start.secsTo(gap_end)));
280 LOG(VB_GENERAL, LOG_ERR,
LOC +
281 QString(
"run() -- error reading from: %1")
287 buffer.append(pkt_buf, len);
298 LOG(VB_GENERAL, LOG_ERR,
LOC +
299 QString(
"run() -- _stream_data_list is empty, %1 buffered")
300 .arg(buffer.size()));
308 remainder = sit.key()->ProcessData
309 (
reinterpret_cast<const uint8_t *
>
310 (buffer.constData()), len);
315 if (remainder > 0 && (len > remainder))
316 buffer.remove(0, len - remainder);
322 LOG(VB_GENERAL, LOG_WARNING,
LOC +
323 QString(
"_running_desired(%1) _error(%2)")
326 LOG(VB_RECORD, LOG_INFO,
LOC +
"run() -- finishing up");
334 LOG(VB_RECORD, LOG_INFO,
LOC +
"run() -- end");
340 LOG(VB_RECORD, LOG_INFO,
LOC +
"open() -- begin");
344 LOG(VB_RECORD, LOG_WARNING,
LOC +
"run() -- Already open.");
360 m_error =
"V4L version 2 required";
380 m_error =
"Failed to allocate DRB buffer";
389 m_error =
"Failed to setup DRB buffer";
395 LOG(VB_RECORD, LOG_INFO,
LOC +
"open() -- done");
403 LOG(VB_RECORD, LOG_INFO,
LOC +
"Configure() -- Already configured.");
407 LOG(VB_RECORD, LOG_INFO,
LOC +
"Configure() -- begin");
413 LOG(VB_RECORD, LOG_ERR,
LOC +
"Configure() -- failed");
426 LOG(VB_RECORD, LOG_INFO,
LOC + QString(
"Options for %1")
434 if (m_maxBitrate < 0 && m_highPeakBitrate > 0)
436 if (m_bitrate < 0 && m_highBitrate > 0)
451 LOG(VB_CHANNEL, LOG_WARNING,
"Audio input not set.");
462 LOG(VB_RECORD, LOG_INFO,
LOC +
"Configure() -- done");
470 if (m_vbi_thread !=
nullptr)
472 m_vbi_thread->wait();
474 m_vbi_thread =
nullptr;
493 LOG(VB_RECORD, LOG_INFO,
LOC +
"Closed.");
501 LOG(VB_RECORD, LOG_INFO,
LOC +
"StartEncoding() -- begin");
508 LOG(VB_GENERAL, LOG_ERR,
LOC +
"V4L2 recorder not initialized.");
517 LOG(VB_GENERAL, LOG_INFO,
LOC +
518 QString(
"Streaming mode %1. Not using it.")
523 for (
int idx = 0; idx < 10; ++idx)
540 for ( ; idx < 50; ++idx)
546 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"StartEncoding read %1 bytes").arg(len));
551 LOG(VB_GENERAL, LOG_ERR,
LOC +
552 "StartEncoding: read failing, re-opening device: " +
ENO);
554 std::this_thread::sleep_for(2ms);
558 LOG(VB_GENERAL, LOG_ERR,
LOC +
559 "StartEncoding: Can't open video device." +
ENO);
560 m_error =
"Failed to start recording";
566 LOG(VB_GENERAL, LOG_ERR,
LOC +
567 QString(
"StartEncoding: read failed, retry in %1 msec:")
568 .arg(100 * idx) +
ENO);
569 std::this_thread::sleep_for(idx * 100us);
574 LOG(VB_GENERAL, LOG_ERR,
LOC +
575 "StartEncoding: read from video device failed." +
ENO);
576 m_error =
"Failed to start recording";
583 LOG(VB_RECORD, LOG_WARNING,
LOC +
584 QString(
"%1 read attempts required to start encoding").arg(idx));
595 LOG(VB_RECORD, LOG_INFO,
LOC +
"Already encoding");
602 LOG(VB_RECORD, LOG_INFO,
LOC +
603 QString(
"StartEncoding() -- %1->%2 listeners")
606 LOG(VB_RECORD, LOG_INFO,
LOC +
"StartEncoding() -- end");
617 LOG(VB_RECORD, LOG_INFO,
LOC +
"StopEncoding: already stopped.");
625 LOG(VB_RECORD, LOG_INFO,
LOC +
626 QString(
"StopEncoding() -- delayed, still have %1 listeners")
633 LOG(VB_GENERAL, LOG_ERR,
LOC +
634 "StopEncoding() -- V4L2enc recorder not started.");
649 std::this_thread::sleep_for(20ms);
655 LOG(VB_RECORD, LOG_INFO,
LOC +
656 QString(
"StopEncoding() -- %1->%2 listeners")
664 LOG(VB_RECORD, LOG_INFO,
LOC +
"RestartEncoding()");
683 if (V4L2_TUNER_MODE_LANG1_LANG2 ==
m_langMode &&
686 LOG(VB_GENERAL, LOG_WARNING,
LOC +
687 "SetLanguageMode() -- Dual audio mode incompatible "
688 "with Layer I audio. Falling back to Main Language");
695 static int find_index(
const std::array<const int,14> &audio_rate,
int value)
697 for (
size_t i = 0; i < audio_rate.size(); ++i)
699 if (audio_rate[i] == value)
713 else if (opt ==
"height")
715 else if (opt ==
"mpeg2bitratemode")
718 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR;
720 else if (opt ==
"mpeg2bitrate")
724 else if (opt ==
"mpeg2maxbitrate")
728 else if (opt ==
"samplerate")
743 else if (opt ==
"mpeg2audbitratel1")
750 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Audiorate(L1): " +
751 QString(
"%1 is invalid").arg(value));
755 else if (opt ==
"mpeg2audbitratel2")
762 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Audiorate(L2): " +
763 QString(
"%1 is invalid").arg(value));
767 else if (opt ==
"mpeg2audbitratel3")
774 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Audiorate(L2): " +
775 QString(
"%1 is invalid").arg(value));
779 else if (opt ==
"mpeg2audvolume")
783 else if (opt ==
"low_mpegbitratemode")
787 else if (opt ==
"medium_mpegbitratemode")
791 else if (opt ==
"high_mpegbitratemode")
795 else if (opt.endsWith(
"avgbitrate"))
797 if (opt.startsWith(
"low"))
799 else if (opt.startsWith(
"medium"))
801 else if (opt.startsWith(
"high"))
806 else if (opt.endsWith(
"peakbitrate"))
808 if (opt.startsWith(
"low"))
810 else if (opt.startsWith(
"medium"))
812 else if (opt.startsWith(
"high"))
822 LOG(VB_RECORD, LOG_INFO,
LOC + QString(
"SetOption('%1', %2) -- success")
823 .arg(opt).arg(value));
839 if (opt ==
"vbidevice")
841 else if (opt ==
"mpeg2streamtype")
851 LOG(VB_GENERAL, LOG_ERR,
LOC +
852 QString(
"MPEG2 stream type %1 is invalid ").arg(value));
855 else if (opt ==
"mpeg2language")
858 int lang_mode = value.toInt(&ok);
861 LOG(VB_GENERAL, LOG_ERR,
LOC +
"MPEG2 language (stereo) flag " +
862 QString(
"'%1' is invalid").arg(value));
879 else if (opt ==
"mpeg2aspectratio")
881 if (value ==
"Square")
883 else if (value ==
"4:3")
885 else if (value ==
"16:9")
887 else if (value ==
"2.21:1")
892 else if (opt ==
"mpeg2audtype")
894 if (value ==
"Layer I")
896 else if (value ==
"Layer II")
898 else if (value ==
"Layer III")
902 LOG(VB_GENERAL, LOG_ERR,
LOC +
"MPEG2 audio layer: " +
903 QString(
"%1 is invalid").arg(value));
906 else if (opt ==
"audiocodec")
908 if (value.startsWith(
"V4L2:"))
920 LOG(VB_RECORD, LOG_INFO,
LOC + QString(
"SetOption('%1', '%2') -- success")
937 LOG(VB_RECORD, LOG_INFO,
LOC + QString(
"GetSignalStrength() -- "
938 "returning cached value (%1)")
948 int bitratemode,
const QString & reason)
950 if (maxbitrate == bitrate)
952 LOG(VB_RECORD, LOG_INFO,
LOC +
953 QString(
"SetBitrate() -- %1 bitrate %2 kbps CBR")
954 .arg(reason).arg(bitrate));
958 LOG(VB_RECORD, LOG_INFO,
LOC +
959 QString(
"SetBitrate() -- %1 bitrate %2/%3 kbps VBR")
960 .arg(reason).arg(bitrate).arg(maxbitrate));
964 if (bitratemode >= 0)
983 for ( ; idx < 10; ++idx)
992 std::this_thread::sleep_for(100us);
999 int pix = width * height;
1028 if (old_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
1030 LOG(VB_RECORD, LOG_INFO,
LOC +
1031 QString(
"Old bitrate %1 CBR").arg(old_avg));
1035 LOG(VB_RECORD, LOG_INFO,
LOC +
1036 QString(
"Old bitrate %1/%2 VBR").arg(old_avg).arg(old_max));
1047 LOG(VB_GENERAL, LOG_INFO,
LOC +
"ConfigureVBI() -- begin");
1050 LOG(VB_RECORD, LOG_INFO,
LOC +
"ConfigureVBI() -- end");