From 269885f7617788e7503e8acff62a1fad7ff5d418 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Thu, 23 Jun 2011 08:50:34 +0100 Subject: [PATCH 1/3] Permit remote transcode in fifodir case --- mythtv/programs/mythtranscode/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 mythtv/programs/mythtranscode/main.cpp diff --git a/mythtv/programs/mythtranscode/main.cpp b/mythtv/programs/mythtranscode/main.cpp old mode 100644 new mode 100755 index 44bc5c96b3d..f6d08006f91 --- a/mythtv/programs/mythtranscode/main.cpp +++ b/mythtv/programs/mythtranscode/main.cpp @@ -412,7 +412,7 @@ int main(int argc, char *argv[]) return QueueTranscodeJob(pginfo, profilename, hostname, useCutlist); } - if (infile.left(7) == "myth://" && (outfile.isNull() || outfile != "-")) + if (infile.left(7) == "myth://" && (outfile.isNull() || outfile != "-") && fifodir.isEmpty()) { VERBOSE(VB_IMPORTANT, QString("Attempted to transcode %1. " "Mythtranscode is currently unable to transcode remote " @@ -421,7 +421,7 @@ int main(int argc, char *argv[]) return GENERIC_EXIT_REMOTE_FILE; } - if (outfile.isNull() && !build_index) + if (outfile.isNull() && !build_index && fifodir.isEmpty()) outfile = infile + ".tmp"; if (jobID >= 0) From 38fa9ede9062b7534eca7ea72eea17095f1aa3e3 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Wed, 6 Jul 2011 09:26:38 +0100 Subject: [PATCH 2/3] Display format information for the fifo data --- .../mythtranscode/commandlineparser.cpp | 2 + mythtv/programs/mythtranscode/main.cpp | 17 +++++- mythtv/programs/mythtranscode/transcode.cpp | 56 ++++++++++++++++++- mythtv/programs/mythtranscode/transcode.h | 2 +- 4 files changed, 74 insertions(+), 3 deletions(-) mode change 100644 => 100755 mythtv/programs/mythtranscode/commandlineparser.cpp mode change 100644 => 100755 mythtv/programs/mythtranscode/transcode.cpp mode change 100644 => 100755 mythtv/programs/mythtranscode/transcode.h diff --git a/mythtv/programs/mythtranscode/commandlineparser.cpp b/mythtv/programs/mythtranscode/commandlineparser.cpp old mode 100644 new mode 100755 index 7411fdd4b03..49c4fef64d7 --- a/mythtv/programs/mythtranscode/commandlineparser.cpp +++ b/mythtv/programs/mythtranscode/commandlineparser.cpp @@ -36,6 +36,8 @@ void MythTranscodeCommandLineParser::LoadArguments(void) "Specifies the outputfile should be entirely keyframes.", ""); add(QStringList( QStringList() << "-f" << "--fifodir" ), "fifodir", "", "Directory in which to write fifos to.", ""); + add("--fifoinfo", "fifoinfo", false, + "Run in fifodir mode, but stop after displaying the fifo data format.", ""); add("--fifosync", "fifosync", false, "Enforce fifo sync.", ""); add("--passthrough", "passthru", false, "Pass through raw, unprocessed audio.", ""); add(QStringList( QStringList() << "-b" << "--buildindex" ), "reindex", false, diff --git a/mythtv/programs/mythtranscode/main.cpp b/mythtv/programs/mythtranscode/main.cpp index f6d08006f91..45e12b80287 100755 --- a/mythtv/programs/mythtranscode/main.cpp +++ b/mythtv/programs/mythtranscode/main.cpp @@ -134,6 +134,7 @@ int main(int argc, char *argv[]) bool useCutlist = false, keyframesonly = false; bool build_index = false, fifosync = false; bool mpeg2 = false; + bool fifo_info = false; QMap settingsOverride; frm_dir_map_t deleteMap; frm_pos_map_t posMap; @@ -274,6 +275,8 @@ int main(int argc, char *argv[]) build_index = true; if (cmdline.toBool("fifodir")) fifodir = cmdline.toString("fifodir"); + if (cmdline.toBool("fifoinfo")) + fifo_info = true; if (cmdline.toBool("fifosync")) fifosync = true; if (cmdline.toBool("recopt")) @@ -357,6 +360,18 @@ int main(int argc, char *argv[]) cerr << "Must specify --fifodir to use --fifosync\n"; return GENERIC_EXIT_INVALID_CMDLINE; } + if (fifo_info && !fifodir.isEmpty()) + { + cerr << "Cannot specify both --fifodir and --fifoinfo\n"; + return GENERIC_EXIT_INVALID_CMDLINE; + } + + if (fifo_info) + { + // Setup a dummy fifodir path, so that the "fifodir" code path + // is taken. The path wont actually be used. + fifodir = "DummyFifoPath"; + } if (!MSqlQuery::testDBConnection()) { @@ -443,7 +458,7 @@ int main(int argc, char *argv[]) result = transcode->TranscodeFile(infile, outfile, profilename, useCutlist, (fifosync || keyframesonly), jobID, - fifodir, deleteMap, AudioTrackNo, + fifodir, fifo_info, deleteMap, AudioTrackNo, passthru); if ((result == REENCODE_OK) && (jobID >= 0)) JobQueue::ChangeJobArgs(jobID, "RENAME_TO_NUV"); diff --git a/mythtv/programs/mythtranscode/transcode.cpp b/mythtv/programs/mythtranscode/transcode.cpp old mode 100644 new mode 100755 index 17522dda643..8f27cf7bdf9 --- a/mythtv/programs/mythtranscode/transcode.cpp +++ b/mythtv/programs/mythtranscode/transcode.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -226,8 +227,9 @@ class AudioReencodeBuffer : public AudioOutput int audiobuffer_len, audiobuffer_frames; int channels, bits, bytes_per_frame, eff_audiorate; long long last_audiotime; + bool m_passthru; private: - bool m_passthru, m_initpassthru; + bool m_initpassthru; }; Transcode::Transcode(ProgramInfo *pginfo) : @@ -378,6 +380,7 @@ int Transcode::TranscodeFile( const QString &profileName, bool honorCutList, bool framecontrol, int jobID, QString fifodir, + bool fifo_info, frm_dir_map_t &deleteMap, int AudioTrackNo, bool passthru) @@ -760,6 +763,57 @@ int Transcode::TranscodeFile( if (!fifodir.isEmpty()) { + AudioPlayer *aplayer = player->GetAudio(); + const char *audio_codec_name; + + switch(aplayer->GetCodec()) + { + case CODEC_ID_AC3: + audio_codec_name = "ac3"; + break; + case CODEC_ID_EAC3: + audio_codec_name = "eac3"; + break; + case CODEC_ID_DTS: + audio_codec_name = "dts"; + break; + case CODEC_ID_TRUEHD: + audio_codec_name = "truehd"; + break; + case CODEC_ID_MP3: + audio_codec_name = "mp3"; + break; + case CODEC_ID_MP2: + audio_codec_name = "mp2"; + break; + default: + audio_codec_name = "unknown"; + } + + if (!arb->m_passthru) + audio_codec_name = "raw"; + + // Display details of the format of the fifo data. + // Circumvent logging system so that output is independent + // of logging level. + cout << "FifoVideoWidth " << video_width << endl; + cout << "FifoVideoHeight " << video_height << endl; + cout << "FifoVideoAspectRatio "<< player->GetVideoAspect() << endl; + cout << "FifoVideoFrameRate " << video_frame_rate << endl; + cout << "FifoAudioFormat " << audio_codec_name << endl; + cout << "FifoAudioChannels " << arb->channels << endl; + cout << "FifoAudioHz " << arb->eff_audiorate << endl; + + if(fifo_info) + { + // Request was for just the format of fifo data, not for + // the actual transcode, so stop here. + unlink(outputname.toLocal8Bit().constData()); + if (player_ctx) + delete player_ctx; + return REENCODE_OK; + } + QString audfifo = fifodir + QString("/audout"); QString vidfifo = fifodir + QString("/vidout"); int audio_size = arb->eff_audiorate * arb->bytes_per_frame; diff --git a/mythtv/programs/mythtranscode/transcode.h b/mythtv/programs/mythtranscode/transcode.h old mode 100644 new mode 100755 index 83aa1d6d11d..b8f62a65f5b --- a/mythtv/programs/mythtranscode/transcode.h +++ b/mythtv/programs/mythtranscode/transcode.h @@ -20,7 +20,7 @@ class Transcode : public QObject const QString &outputname, const QString &profileName, bool honorCutList, bool framecontrol, int jobID, - QString fifodir, frm_dir_map_t &deleteMap, + QString fifodir, bool fifo_info, frm_dir_map_t &deleteMap, int AudioTrackNo, bool passthru = false); void ShowProgress(bool val) { showprogress = val; } void SetRecorderOptions(QString options) { recorderOptions = options; } From 1e33dcf22fe8c44958303e3bc77c644f25fbd58d Mon Sep 17 00:00:00 2001 From: Gavin Hurlbut Date: Thu, 7 Jul 2011 21:12:25 -0700 Subject: [PATCH 3/3] Change the --fifo-info output to use logging The use of cout should be constrained to things that should be CLI-only. It is good to have this output actually logged. Also made mythtranscode use a CleanupGuard so it cleans up gContext the same as other binaries do. This considerably cleans up the shutdown. --- mythtv/programs/mythtranscode/main.cpp | 42 +++++++++++++++++++-- mythtv/programs/mythtranscode/transcode.cpp | 25 ++++++------ mythtv/programs/mythtranscode/transcode.h | 2 +- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/mythtv/programs/mythtranscode/main.cpp b/mythtv/programs/mythtranscode/main.cpp index 45e12b80287..374d116713c 100755 --- a/mythtv/programs/mythtranscode/main.cpp +++ b/mythtv/programs/mythtranscode/main.cpp @@ -121,6 +121,34 @@ static int QueueTranscodeJob(ProgramInfo *pginfo, QString profile, return GENERIC_EXIT_DB_ERROR; } +namespace +{ + void cleanup() + { + delete gContext; + gContext = NULL; + + } + + class CleanupGuard + { + public: + typedef void (*CleanupFunc)(); + + public: + CleanupGuard(CleanupFunc cleanFunction) : + m_cleanFunction(cleanFunction) {} + + ~CleanupGuard() + { + m_cleanFunction(); + } + + private: + CleanupFunc m_cleanFunction; + }; +} + int main(int argc, char *argv[]) { uint chanid; @@ -302,6 +330,7 @@ int main(int argc, char *argv[]) if (cmdline.toBool("passthru")) passthru = true; + CleanupGuard callCleanup(cleanup); // Load the context gContext = new MythContext(MYTH_BINARY_VERSION); if (!gContext->Init(false)) @@ -427,7 +456,8 @@ int main(int argc, char *argv[]) return QueueTranscodeJob(pginfo, profilename, hostname, useCutlist); } - if (infile.left(7) == "myth://" && (outfile.isNull() || outfile != "-") && fifodir.isEmpty()) + if (infile.left(7) == "myth://" && (outfile.isNull() || outfile != "-") && + fifodir.isEmpty()) { VERBOSE(VB_IMPORTANT, QString("Attempted to transcode %1. " "Mythtranscode is currently unable to transcode remote " @@ -458,12 +488,18 @@ int main(int argc, char *argv[]) result = transcode->TranscodeFile(infile, outfile, profilename, useCutlist, (fifosync || keyframesonly), jobID, - fifodir, fifo_info, deleteMap, AudioTrackNo, - passthru); + fifodir, fifo_info, deleteMap, + AudioTrackNo, passthru); if ((result == REENCODE_OK) && (jobID >= 0)) JobQueue::ChangeJobArgs(jobID, "RENAME_TO_NUV"); } + if (fifo_info) + { + delete transcode; + return GENERIC_EXIT_OK; + } + int exitcode = GENERIC_EXIT_OK; if ((result == REENCODE_MPEG2TRANS) || mpeg2 || build_index) { diff --git a/mythtv/programs/mythtranscode/transcode.cpp b/mythtv/programs/mythtranscode/transcode.cpp index 8f27cf7bdf9..52d99b33f8d 100755 --- a/mythtv/programs/mythtranscode/transcode.cpp +++ b/mythtv/programs/mythtranscode/transcode.cpp @@ -794,23 +794,26 @@ int Transcode::TranscodeFile( audio_codec_name = "raw"; // Display details of the format of the fifo data. - // Circumvent logging system so that output is independent - // of logging level. - cout << "FifoVideoWidth " << video_width << endl; - cout << "FifoVideoHeight " << video_height << endl; - cout << "FifoVideoAspectRatio "<< player->GetVideoAspect() << endl; - cout << "FifoVideoFrameRate " << video_frame_rate << endl; - cout << "FifoAudioFormat " << audio_codec_name << endl; - cout << "FifoAudioChannels " << arb->channels << endl; - cout << "FifoAudioHz " << arb->eff_audiorate << endl; + LOG(VB_GENERAL, LOG_INFO, + QString("FifoVideoWidth %1").arg(video_width)); + LOG(VB_GENERAL, LOG_INFO, + QString("FifoVideoHeight %1").arg(video_height)); + LOG(VB_GENERAL, LOG_INFO, + QString("FifoVideoAspectRatio %1").arg(player->GetVideoAspect())); + LOG(VB_GENERAL, LOG_INFO, + QString("FifoVideoFrameRate %1").arg(video_frame_rate)); + LOG(VB_GENERAL, LOG_INFO, + QString("FifoAudioFormat %1").arg(audio_codec_name)); + LOG(VB_GENERAL, LOG_INFO, + QString("FifoAudioChannels %1").arg(arb->channels)); + LOG(VB_GENERAL, LOG_INFO, + QString("FifoAudioSampleRate %1").arg(arb->eff_audiorate)); if(fifo_info) { // Request was for just the format of fifo data, not for // the actual transcode, so stop here. unlink(outputname.toLocal8Bit().constData()); - if (player_ctx) - delete player_ctx; return REENCODE_OK; } diff --git a/mythtv/programs/mythtranscode/transcode.h b/mythtv/programs/mythtranscode/transcode.h index b8f62a65f5b..19e864954a2 100755 --- a/mythtv/programs/mythtranscode/transcode.h +++ b/mythtv/programs/mythtranscode/transcode.h @@ -15,6 +15,7 @@ class Transcode : public QObject { public: Transcode(ProgramInfo *pginfo); + ~Transcode(); int TranscodeFile( const QString &inputname, const QString &outputname, @@ -26,7 +27,6 @@ class Transcode : public QObject void SetRecorderOptions(QString options) { recorderOptions = options; } private: - ~Transcode(); bool GetProfile(QString profileName, QString encodingType, int height, int frameRate); void ReencoderAddKFA(long curframe, long lastkey, long num_keyframes);