OK, now gapless transcoding should work for reals.

This commit is contained in:
casey langen 2017-11-21 11:57:19 -08:00
parent e85f40bdec
commit ee22b5f6f6
2 changed files with 15 additions and 4 deletions

View File

@ -509,7 +509,8 @@ int HttpServer::HandleAudioTrackRequest(
MHD_add_response_header(response, "Cache-Control", value.c_str());
}
MHD_add_response_header(response, "Content-Type", contentType(filename).c_str());
std::string type = isOnDemandTranscoder ? "audio/mpeg" : contentType(filename);
MHD_add_response_header(response, "Content-Type", type.c_str());
MHD_add_response_header(response, "Server", "musikcube websocket_remote");
if ((rangeVal && strlen(rangeVal)) || range->from > 0) {

View File

@ -188,6 +188,8 @@ PositionType TranscodingDataStream::Read(void *buffer, PositionType bytesToRead)
lame_set_in_samplerate(this->lame, this->pcmBuffer->SampleRate());
lame_set_VBR(lame, vbr_off);
lame_set_VBR_mean_bitrate_kbps(lame, this->bitrate);
lame_set_brate(lame, this->bitrate);
lame_set_quality(lame, 5);
lame_set_out_samplerate(lame, this->pcmBuffer->SampleRate());
lame_set_bWriteVbrTag(lame, 1);
lame_init_params(lame);
@ -324,13 +326,11 @@ PositionType TranscodingDataStream::Read(void *buffer, PositionType bytesToRead)
encodedBytes.realloc(7200);
}
int count = lame_encode_flush_nogap(
int count = lame_encode_flush(
lame,
encodedBytes.data,
encodedBytes.length);
lame_init_bitstream(lame); /* writes XING header for gapless playback */
this->eof = true;
if (count >= 0) {
@ -338,6 +338,16 @@ PositionType TranscodingDataStream::Read(void *buffer, PositionType bytesToRead)
if (this->outFile) {
fwrite(encodedBytes.data, 1, count, this->outFile);
/* need to make sure we write the LAME header, otherwise
gapless playback won't work! */
unsigned char header[2800]; /* max frame size */
size_t headerSize = lame_get_lametag_frame(lame, header, sizeof(header));
if (headerSize) {
fseek(this->outFile, 0, SEEK_SET);
fwrite(header, 1, headerSize, this->outFile);
}
fclose(this->outFile);
this->outFile = nullptr;