mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +00:00
OK, now gapless transcoding should work for reals.
This commit is contained in:
parent
e85f40bdec
commit
ee22b5f6f6
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user