mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-17 19:19:16 +01:00
Merge pull request #45 from bnnm/ffmpeg-fixes3
FFmpeg: keep block size constant (for edge loops), don't write on EOF
This commit is contained in:
commit
05f86831bf
@ -90,7 +90,7 @@ void decode_ffmpeg(VGMSTREAM *vgmstream,
|
|||||||
|
|
||||||
int framesReadNow;
|
int framesReadNow;
|
||||||
|
|
||||||
if (data->totalFrames && data->framesRead >= data->totalFrames) {
|
if ((data->totalFrames && data->framesRead >= data->totalFrames) || data->endOfStream || data->endOfAudio) {
|
||||||
memset(outbuf, 0, samples_to_do * channels * sizeof(sample));
|
memset(outbuf, 0, samples_to_do * channels * sizeof(sample));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ VGMSTREAM * init_vgmstream_internal(STREAMFILE *streamFile, int do_dfs) {
|
|||||||
|
|
||||||
/* fail if there is nothing to play
|
/* fail if there is nothing to play
|
||||||
* (without this check vgmstream can generate empty files) */
|
* (without this check vgmstream can generate empty files) */
|
||||||
if ( vgmstream->num_samples==0 ) {
|
if (vgmstream->num_samples <= 0) {
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1084,9 +1084,9 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
|
|||||||
case coding_FFmpeg:
|
case coding_FFmpeg:
|
||||||
{
|
{
|
||||||
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
|
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
|
||||||
if (vgmstream->codec_data) {
|
if (data) {
|
||||||
int64_t samplesRemain = data->totalFrames - data->framesRead;
|
/* must know the full block size for edge loops */
|
||||||
return samplesRemain > data->samplesPerBlock ? data->samplesPerBlock : samplesRemain;
|
return data->samplesPerBlock;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1805,8 +1805,16 @@ int vgmstream_do_loop(VGMSTREAM * vgmstream) {
|
|||||||
data->samplesToDiscard = (int)ts;
|
data->samplesToDiscard = (int)ts;
|
||||||
ts = 0;
|
ts = 0;
|
||||||
}
|
}
|
||||||
data->framesRead = (int)ts;
|
|
||||||
ts = data->framesRead * (data->formatCtx->duration) / data->totalFrames;
|
/* todo fix this properly */
|
||||||
|
if (data->totalFrames) {
|
||||||
|
data->framesRead = (int)ts;
|
||||||
|
ts = data->framesRead * (data->formatCtx->duration) / data->totalFrames;
|
||||||
|
} else {
|
||||||
|
data->samplesToDiscard = vgmstream->loop_start_sample;
|
||||||
|
data->framesRead = 0;
|
||||||
|
ts = 0;
|
||||||
|
}
|
||||||
|
|
||||||
avformat_seek_file(data->formatCtx, -1, ts - 1000, ts, ts, AVSEEK_FLAG_ANY);
|
avformat_seek_file(data->formatCtx, -1, ts - 1000, ts, ts, AVSEEK_FLAG_ANY);
|
||||||
avcodec_flush_buffers(data->codecCtx);
|
avcodec_flush_buffers(data->codecCtx);
|
||||||
|
@ -869,7 +869,7 @@ typedef struct {
|
|||||||
int bitsPerSample;
|
int bitsPerSample;
|
||||||
int floatingPoint;
|
int floatingPoint;
|
||||||
int sampleRate;
|
int sampleRate;
|
||||||
int64_t totalFrames;
|
int64_t totalFrames; // sample count, or 0 if unknown
|
||||||
int64_t framesRead;
|
int64_t framesRead;
|
||||||
int bitrate;
|
int bitrate;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user