mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-28 08:20:54 +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;
|
||||
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ VGMSTREAM * init_vgmstream_internal(STREAMFILE *streamFile, int do_dfs) {
|
||||
|
||||
/* fail if there is nothing to play
|
||||
* (without this check vgmstream can generate empty files) */
|
||||
if ( vgmstream->num_samples==0 ) {
|
||||
if (vgmstream->num_samples <= 0) {
|
||||
close_vgmstream(vgmstream);
|
||||
continue;
|
||||
}
|
||||
@ -1084,9 +1084,9 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
|
||||
case coding_FFmpeg:
|
||||
{
|
||||
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
|
||||
if (vgmstream->codec_data) {
|
||||
int64_t samplesRemain = data->totalFrames - data->framesRead;
|
||||
return samplesRemain > data->samplesPerBlock ? data->samplesPerBlock : samplesRemain;
|
||||
if (data) {
|
||||
/* must know the full block size for edge loops */
|
||||
return data->samplesPerBlock;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1805,8 +1805,16 @@ int vgmstream_do_loop(VGMSTREAM * vgmstream) {
|
||||
data->samplesToDiscard = (int)ts;
|
||||
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);
|
||||
avcodec_flush_buffers(data->codecCtx);
|
||||
|
@ -869,7 +869,7 @@ typedef struct {
|
||||
int bitsPerSample;
|
||||
int floatingPoint;
|
||||
int sampleRate;
|
||||
int64_t totalFrames;
|
||||
int64_t totalFrames; // sample count, or 0 if unknown
|
||||
int64_t framesRead;
|
||||
int bitrate;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user