Permalink
Browse files

HLS Fix and mythtranscode optimization.

- 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...
1 parent 28fd68a commit aef3087b25b8b317123d3ad058fc4fdb8a80540a @cpinkham cpinkham committed Jul 20, 2012
Showing with 47 additions and 62 deletions.
  1. +47 −62 mythtv/programs/mythtranscode/transcode.cpp
View
109 mythtv/programs/mythtranscode/transcode.cpp
@@ -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);
@@ -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);
@@ -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)

0 comments on commit aef3087

Please sign in to comment.