Skip to content

Commit

Permalink
HLS Fix and mythtranscode optimization.
Browse files Browse the repository at this point in the history
- Eliminate AudioReencodeBuffer::GetCount() usage and method itself.

- Call HTTPLiveStream::InitForWrite() when we create a live stream
using the command line invocation of mythtranscode.

Fixes #10923.
  • Loading branch information
cpinkham committed Jul 20, 2012
1 parent 28fd68a commit aef3087
Showing 1 changed file with 47 additions and 62 deletions.
109 changes: 47 additions & 62 deletions mythtv/programs/mythtranscode/transcode.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -244,27 +244,6 @@ class AudioReencodeBuffer : public AudioOutput
return NULL; return NULL;
} }


int GetCount(long long time)
{
QMutexLocker locker(&m_bufferMutex);

if (m_bufferList.isEmpty())
return 0;

int count = 0;
for (QList<AudioBuffer *>::iterator it = m_bufferList.begin();
it != m_bufferList.end(); ++it)
{
AudioBuffer *ab = *it;

if (ab->m_time <= time)
count++;
else
break;
}
return count;
}

long long GetSamples(long long time) long long GetSamples(long long time)
{ {
QMutexLocker locker(&m_bufferMutex); QMutexLocker locker(&m_bufferMutex);
Expand Down Expand Up @@ -1139,17 +1118,26 @@ int Transcode::TranscodeFile(const QString &inputname,
avfw->SetAudioCodec("libmp3lame"); avfw->SetAudioCodec("libmp3lame");


if (hlsStreamID == -1) if (hlsStreamID == -1)
{
hls = new HTTPLiveStream(inputname, newWidth, newHeight, hls = new HTTPLiveStream(inputname, newWidth, newHeight,
cmdBitrate, cmdBitrate,
cmdAudioBitrate, hlsMaxSegments, cmdAudioBitrate, hlsMaxSegments,
segmentSize, audioOnlyBitrate); segmentSize, audioOnlyBitrate);


hlsStreamID = hls->GetStreamID();
if (!hls || hlsStreamID == -1)
{
LOG(VB_GENERAL, LOG_ERR, "Unable to create new stream");
SetPlayerContext(NULL);
return REENCODE_ERROR;
}
}

hls->UpdateStatus(kHLSStatusStarting); hls->UpdateStatus(kHLSStatusStarting);
hls->UpdateStatusMessage("Transcoding Starting"); hls->UpdateStatusMessage("Transcoding Starting");
hls->UpdateSizeInfo(newWidth, newHeight, video_width, video_height); hls->UpdateSizeInfo(newWidth, newHeight, video_width, video_height);


if ((hlsStreamID != -1) && if (!hls->InitForWrite())
(!hls->InitForWrite()))
{ {
LOG(VB_GENERAL, LOG_ERR, "hls->InitForWrite() failed"); LOG(VB_GENERAL, LOG_ERR, "hls->InitForWrite() failed");
SetPlayerContext(NULL); SetPlayerContext(NULL);
Expand Down Expand Up @@ -1942,57 +1930,54 @@ int Transcode::TranscodeFile(const QString &inputname,
} }


// audio is fully decoded, so we need to reencode it // audio is fully decoded, so we need to reencode it
if (arb->GetCount(lastWrittenTime)) AudioBuffer *ab = NULL;
while ((ab = arb->GetData(lastWrittenTime)) != NULL)
{ {
AudioBuffer *ab = NULL; unsigned char *buf = (unsigned char *)ab->data();
while ((ab = arb->GetData(lastWrittenTime)) != NULL) if (avfMode)
{ {
unsigned char *buf = (unsigned char *)ab->data(); if (did_ff != 1)
if (avfMode)
{ {
if (did_ff != 1) long long tc = ab->m_time - timecodeOffset;
{ avfw->WriteAudioFrame(buf, audioFrame, tc);
long long tc = ab->m_time - timecodeOffset;
avfw->WriteAudioFrame(buf, audioFrame, tc);


if (avfw2) if (avfw2)
{
if ((avfw2->GetTimecodeOffset() == -1) &&
(avfw->GetTimecodeOffset() != -1))
{ {
if ((avfw2->GetTimecodeOffset() == -1) && avfw2->SetTimecodeOffset(
(avfw->GetTimecodeOffset() != -1)) avfw->GetTimecodeOffset());
{
avfw2->SetTimecodeOffset(
avfw->GetTimecodeOffset());
}

tc = ab->m_time - timecodeOffset;
avfw2->WriteAudioFrame(buf, audioFrame, tc);
} }


++audioFrame; tc = ab->m_time - timecodeOffset;
avfw2->WriteAudioFrame(buf, audioFrame, tc);
} }

++audioFrame;
} }
else }
else
{
nvr->SetOption("audioframesize", ab->size());
nvr->WriteAudio(buf, audioFrame++,
ab->m_time - timecodeOffset);
if (nvr->IsErrored())
{ {
nvr->SetOption("audioframesize", ab->size()); LOG(VB_GENERAL, LOG_ERR,
nvr->WriteAudio(buf, audioFrame++, "Transcode: Encountered irrecoverable error in "
ab->m_time - timecodeOffset); "NVR::WriteAudio");
if (nvr->IsErrored())
{ av_free(newFrame);
LOG(VB_GENERAL, LOG_ERR, SetPlayerContext(NULL);
"Transcode: Encountered irrecoverable error in " if (frameQueue)
"NVR::WriteAudio"); frameQueue->stop();

delete ab;
av_free(newFrame); return REENCODE_ERROR;
SetPlayerContext(NULL);
if (frameQueue)
frameQueue->stop();
delete ab;
return REENCODE_ERROR;
}
} }

delete ab;
} }

delete ab;
} }


if (!avfMode) if (!avfMode)
Expand Down

0 comments on commit aef3087

Please sign in to comment.