Skip to content

Commit

Permalink
Merge branch 'glidos-master'
Browse files Browse the repository at this point in the history
Fixes #9902.

This adds a --fifo-info command-line argument to mythtranscode, and also allows
for remote transcoding when running in fifo mode.  Additionally, the shutdown
of mythtranscode has been tidied up by using a CleanupGuard that matches that
of mythcommflag and other binaries.
  • Loading branch information
Beirdo committed Jul 8, 2011
2 parents 374175d + 1e33dcf commit f40668e
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 7 deletions.
2 changes: 2 additions & 0 deletions mythtv/programs/mythtranscode/commandlineparser.cpp 100644 → 100755
Expand Up @@ -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,
Expand Down
59 changes: 55 additions & 4 deletions mythtv/programs/mythtranscode/main.cpp 100644 → 100755
Expand Up @@ -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;
Expand All @@ -134,6 +162,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<QString, QString> settingsOverride;
frm_dir_map_t deleteMap;
frm_pos_map_t posMap;
Expand Down Expand Up @@ -274,6 +303,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"))
Expand All @@ -299,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))
Expand Down Expand Up @@ -357,6 +389,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())
{
Expand Down Expand Up @@ -412,7 +456,8 @@ 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 "
Expand All @@ -421,7 +466,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)
Expand All @@ -443,12 +488,18 @@ int main(int argc, char *argv[])
result = transcode->TranscodeFile(infile, outfile,
profilename, useCutlist,
(fifosync || keyframesonly), jobID,
fifodir, 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)
{
Expand Down
59 changes: 58 additions & 1 deletion mythtv/programs/mythtranscode/transcode.cpp 100644 → 100755
@@ -1,5 +1,6 @@
#include <fcntl.h>
#include <math.h>
#include <iostream>

#include <QStringList>
#include <QMap>
Expand Down Expand Up @@ -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) :
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -760,6 +763,60 @@ 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.
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());
return REENCODE_OK;
}

QString audfifo = fifodir + QString("/audout");
QString vidfifo = fifodir + QString("/vidout");
int audio_size = arb->eff_audiorate * arb->bytes_per_frame;
Expand Down
4 changes: 2 additions & 2 deletions mythtv/programs/mythtranscode/transcode.h 100644 → 100755
Expand Up @@ -15,18 +15,18 @@ class Transcode : public QObject
{
public:
Transcode(ProgramInfo *pginfo);
~Transcode();
int TranscodeFile(
const QString &inputname,
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; }

private:
~Transcode();
bool GetProfile(QString profileName, QString encodingType, int height,
int frameRate);
void ReencoderAddKFA(long curframe, long lastkey, long num_keyframes);
Expand Down

0 comments on commit f40668e

Please sign in to comment.