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
Expand Up @@ -244,27 +244,6 @@ class AudioReencodeBuffer : public AudioOutput
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)
{
QMutexLocker locker(&m_bufferMutex);
Expand Down Expand Up @@ -1139,17 +1118,26 @@ int Transcode::TranscodeFile(const QString &inputname,
avfw->SetAudioCodec("libmp3lame");

if (hlsStreamID == -1)
{
hls = new HTTPLiveStream(inputname, newWidth, newHeight,
cmdBitrate,
cmdAudioBitrate, hlsMaxSegments,
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->UpdateStatusMessage("Transcoding Starting");
hls->UpdateSizeInfo(newWidth, newHeight, video_width, video_height);

if ((hlsStreamID != -1) &&
(!hls->InitForWrite()))
if (!hls->InitForWrite())
{
LOG(VB_GENERAL, LOG_ERR, "hls->InitForWrite() failed");
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
if (arb->GetCount(lastWrittenTime))
AudioBuffer *ab = NULL;
while ((ab = arb->GetData(lastWrittenTime)) != NULL)
{
AudioBuffer *ab = NULL;
while ((ab = arb->GetData(lastWrittenTime)) != NULL)
unsigned char *buf = (unsigned char *)ab->data();
if (avfMode)
{
unsigned char *buf = (unsigned char *)ab->data();
if (avfMode)
if (did_ff != 1)
{
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) &&
(avfw->GetTimecodeOffset() != -1))
{
avfw2->SetTimecodeOffset(
avfw->GetTimecodeOffset());
}

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

++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());
nvr->WriteAudio(buf, audioFrame++,
ab->m_time - timecodeOffset);
if (nvr->IsErrored())
{
LOG(VB_GENERAL, LOG_ERR,
"Transcode: Encountered irrecoverable error in "
"NVR::WriteAudio");

av_free(newFrame);
SetPlayerContext(NULL);
if (frameQueue)
frameQueue->stop();
delete ab;
return REENCODE_ERROR;
}
LOG(VB_GENERAL, LOG_ERR,
"Transcode: Encountered irrecoverable error in "
"NVR::WriteAudio");

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

delete ab;
}

delete ab;
}

if (!avfMode)
Expand Down

0 comments on commit aef3087

Please sign in to comment.