mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avdevice/oss_dec: account for sample size when computing timestamp
Don't assume each sample is one byte in size. Doing so results in wrong and occasionally non-monotonically-increasing timestamps. Fix nearby cosmetic typo. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
fee765c207
commit
b3e261bab3
@ -102,9 +102,11 @@ int ff_oss_audio_open(AVFormatContext *s1, int is_output,
|
|||||||
switch(tmp) {
|
switch(tmp) {
|
||||||
case AFMT_S16_LE:
|
case AFMT_S16_LE:
|
||||||
s->codec_id = AV_CODEC_ID_PCM_S16LE;
|
s->codec_id = AV_CODEC_ID_PCM_S16LE;
|
||||||
|
s->sample_size = 2;
|
||||||
break;
|
break;
|
||||||
case AFMT_S16_BE:
|
case AFMT_S16_BE:
|
||||||
s->codec_id = AV_CODEC_ID_PCM_S16BE;
|
s->codec_id = AV_CODEC_ID_PCM_S16BE;
|
||||||
|
s->sample_size = 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
av_log(s1, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n");
|
av_log(s1, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n");
|
||||||
@ -112,7 +114,7 @@ int ff_oss_audio_open(AVFormatContext *s1, int is_output,
|
|||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
}
|
||||||
err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
|
err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
|
||||||
CHECK_IOCTL_ERROR(SNDCTL_DSP_SETFMTS)
|
CHECK_IOCTL_ERROR(SNDCTL_DSP_SETFMT)
|
||||||
|
|
||||||
tmp = (s->channels == 2);
|
tmp = (s->channels == 2);
|
||||||
err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
|
err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
|
||||||
|
@ -30,6 +30,7 @@ typedef struct OSSAudioData {
|
|||||||
AVClass *class;
|
AVClass *class;
|
||||||
int fd;
|
int fd;
|
||||||
int sample_rate;
|
int sample_rate;
|
||||||
|
int sample_size; /* in bytes ! */
|
||||||
int channels;
|
int channels;
|
||||||
int frame_size; /* in bytes ! */
|
int frame_size; /* in bytes ! */
|
||||||
enum AVCodecID codec_id;
|
enum AVCodecID codec_id;
|
||||||
|
@ -91,7 +91,7 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||||||
bdelay += abufi.bytes;
|
bdelay += abufi.bytes;
|
||||||
}
|
}
|
||||||
/* subtract time represented by the number of bytes in the audio fifo */
|
/* subtract time represented by the number of bytes in the audio fifo */
|
||||||
cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels);
|
cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->sample_size * s->channels);
|
||||||
|
|
||||||
/* convert to wanted units */
|
/* convert to wanted units */
|
||||||
pkt->pts = cur_time;
|
pkt->pts = cur_time;
|
||||||
|
Loading…
Reference in New Issue
Block a user