Skip to content

Commit aef3087

Browse files
committed
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.
1 parent 28fd68a commit aef3087

File tree

1 file changed

+47
-62
lines changed

1 file changed

+47
-62
lines changed

mythtv/programs/mythtranscode/transcode.cpp

Lines changed: 47 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -244,27 +244,6 @@ class AudioReencodeBuffer : public AudioOutput
244244
return NULL;
245245
}
246246

247-
int GetCount(long long time)
248-
{
249-
QMutexLocker locker(&m_bufferMutex);
250-
251-
if (m_bufferList.isEmpty())
252-
return 0;
253-
254-
int count = 0;
255-
for (QList<AudioBuffer *>::iterator it = m_bufferList.begin();
256-
it != m_bufferList.end(); ++it)
257-
{
258-
AudioBuffer *ab = *it;
259-
260-
if (ab->m_time <= time)
261-
count++;
262-
else
263-
break;
264-
}
265-
return count;
266-
}
267-
268247
long long GetSamples(long long time)
269248
{
270249
QMutexLocker locker(&m_bufferMutex);
@@ -1139,17 +1118,26 @@ int Transcode::TranscodeFile(const QString &inputname,
11391118
avfw->SetAudioCodec("libmp3lame");
11401119

11411120
if (hlsStreamID == -1)
1121+
{
11421122
hls = new HTTPLiveStream(inputname, newWidth, newHeight,
11431123
cmdBitrate,
11441124
cmdAudioBitrate, hlsMaxSegments,
11451125
segmentSize, audioOnlyBitrate);
11461126

1127+
hlsStreamID = hls->GetStreamID();
1128+
if (!hls || hlsStreamID == -1)
1129+
{
1130+
LOG(VB_GENERAL, LOG_ERR, "Unable to create new stream");
1131+
SetPlayerContext(NULL);
1132+
return REENCODE_ERROR;
1133+
}
1134+
}
1135+
11471136
hls->UpdateStatus(kHLSStatusStarting);
11481137
hls->UpdateStatusMessage("Transcoding Starting");
11491138
hls->UpdateSizeInfo(newWidth, newHeight, video_width, video_height);
11501139

1151-
if ((hlsStreamID != -1) &&
1152-
(!hls->InitForWrite()))
1140+
if (!hls->InitForWrite())
11531141
{
11541142
LOG(VB_GENERAL, LOG_ERR, "hls->InitForWrite() failed");
11551143
SetPlayerContext(NULL);
@@ -1942,57 +1930,54 @@ int Transcode::TranscodeFile(const QString &inputname,
19421930
}
19431931

19441932
// audio is fully decoded, so we need to reencode it
1945-
if (arb->GetCount(lastWrittenTime))
1933+
AudioBuffer *ab = NULL;
1934+
while ((ab = arb->GetData(lastWrittenTime)) != NULL)
19461935
{
1947-
AudioBuffer *ab = NULL;
1948-
while ((ab = arb->GetData(lastWrittenTime)) != NULL)
1936+
unsigned char *buf = (unsigned char *)ab->data();
1937+
if (avfMode)
19491938
{
1950-
unsigned char *buf = (unsigned char *)ab->data();
1951-
if (avfMode)
1939+
if (did_ff != 1)
19521940
{
1953-
if (did_ff != 1)
1954-
{
1955-
long long tc = ab->m_time - timecodeOffset;
1956-
avfw->WriteAudioFrame(buf, audioFrame, tc);
1941+
long long tc = ab->m_time - timecodeOffset;
1942+
avfw->WriteAudioFrame(buf, audioFrame, tc);
19571943

1958-
if (avfw2)
1944+
if (avfw2)
1945+
{
1946+
if ((avfw2->GetTimecodeOffset() == -1) &&
1947+
(avfw->GetTimecodeOffset() != -1))
19591948
{
1960-
if ((avfw2->GetTimecodeOffset() == -1) &&
1961-
(avfw->GetTimecodeOffset() != -1))
1962-
{
1963-
avfw2->SetTimecodeOffset(
1964-
avfw->GetTimecodeOffset());
1965-
}
1966-
1967-
tc = ab->m_time - timecodeOffset;
1968-
avfw2->WriteAudioFrame(buf, audioFrame, tc);
1949+
avfw2->SetTimecodeOffset(
1950+
avfw->GetTimecodeOffset());
19691951
}
19701952

1971-
++audioFrame;
1953+
tc = ab->m_time - timecodeOffset;
1954+
avfw2->WriteAudioFrame(buf, audioFrame, tc);
19721955
}
1956+
1957+
++audioFrame;
19731958
}
1974-
else
1959+
}
1960+
else
1961+
{
1962+
nvr->SetOption("audioframesize", ab->size());
1963+
nvr->WriteAudio(buf, audioFrame++,
1964+
ab->m_time - timecodeOffset);
1965+
if (nvr->IsErrored())
19751966
{
1976-
nvr->SetOption("audioframesize", ab->size());
1977-
nvr->WriteAudio(buf, audioFrame++,
1978-
ab->m_time - timecodeOffset);
1979-
if (nvr->IsErrored())
1980-
{
1981-
LOG(VB_GENERAL, LOG_ERR,
1982-
"Transcode: Encountered irrecoverable error in "
1983-
"NVR::WriteAudio");
1984-
1985-
av_free(newFrame);
1986-
SetPlayerContext(NULL);
1987-
if (frameQueue)
1988-
frameQueue->stop();
1989-
delete ab;
1990-
return REENCODE_ERROR;
1991-
}
1967+
LOG(VB_GENERAL, LOG_ERR,
1968+
"Transcode: Encountered irrecoverable error in "
1969+
"NVR::WriteAudio");
1970+
1971+
av_free(newFrame);
1972+
SetPlayerContext(NULL);
1973+
if (frameQueue)
1974+
frameQueue->stop();
1975+
delete ab;
1976+
return REENCODE_ERROR;
19921977
}
1993-
1994-
delete ab;
19951978
}
1979+
1980+
delete ab;
19961981
}
19971982

19981983
if (!avfMode)

0 commit comments

Comments
 (0)