Skip to content

Commit b3e261b

Browse files
mhjacobsoncus
authored andcommitted
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 <[email protected]>
1 parent fee765c commit b3e261b

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

libavdevice/oss.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,19 @@ int ff_oss_audio_open(AVFormatContext *s1, int is_output,
102102
switch(tmp) {
103103
case AFMT_S16_LE:
104104
s->codec_id = AV_CODEC_ID_PCM_S16LE;
105+
s->sample_size = 2;
105106
break;
106107
case AFMT_S16_BE:
107108
s->codec_id = AV_CODEC_ID_PCM_S16BE;
109+
s->sample_size = 2;
108110
break;
109111
default:
110112
av_log(s1, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n");
111113
close(audio_fd);
112114
return AVERROR(EIO);
113115
}
114116
err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
115-
CHECK_IOCTL_ERROR(SNDCTL_DSP_SETFMTS)
117+
CHECK_IOCTL_ERROR(SNDCTL_DSP_SETFMT)
116118

117119
tmp = (s->channels == 2);
118120
err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);

libavdevice/oss.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct OSSAudioData {
3030
AVClass *class;
3131
int fd;
3232
int sample_rate;
33+
int sample_size; /* in bytes ! */
3334
int channels;
3435
int frame_size; /* in bytes ! */
3536
enum AVCodecID codec_id;

libavdevice/oss_dec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
9191
bdelay += abufi.bytes;
9292
}
9393
/* subtract time represented by the number of bytes in the audio fifo */
94-
cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels);
94+
cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->sample_size * s->channels);
9595

9696
/* convert to wanted units */
9797
pkt->pts = cur_time;

0 commit comments

Comments
 (0)