#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#ifdef __OpenBSD__
+#include <soundcard.h>
+#else
#include <sys/soundcard.h>
+#endif
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int frame_size; /* in bytes ! */
int codec_id;
int flip_left : 1;
- UINT8 buffer[AUDIO_BLOCK_SIZE];
+ uint8_t buffer[AUDIO_BLOCK_SIZE];
int buffer_ptr;
} AudioData;
/* open linux audio device */
if (!audio_device)
+#ifdef __OpenBSD__
+ audio_device = "/dev/sound";
+#else
audio_device = "/dev/dsp";
+#endif
if (is_output)
audio_fd = open(audio_device, O_WRONLY);
audio_fd = open(audio_device, O_RDONLY);
if (audio_fd < 0) {
perror(audio_device);
- return -EIO;
+ return AVERROR_IO;
}
if (flip && *flip == '1') {
s->codec_id = CODEC_ID_PCM_S16BE;
break;
default:
- fprintf(stderr, "Soundcard does not support 16 bit sample format\n");
+ av_log(NULL, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n");
close(audio_fd);
- return -EIO;
+ return AVERROR_IO;
}
err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
if (err < 0) {
return 0;
fail:
close(audio_fd);
- return -EIO;
+ return AVERROR_IO;
}
static int audio_close(AudioData *s)
int ret;
st = s1->streams[0];
- s->sample_rate = st->codec.sample_rate;
- s->channels = st->codec.channels;
+ s->sample_rate = st->codec->sample_rate;
+ s->channels = st->codec->channels;
ret = audio_open(s, 1, NULL);
if (ret < 0) {
- return -EIO;
+ return AVERROR_IO;
} else {
return 0;
}
}
-static int audio_write_packet(AVFormatContext *s1, int stream_index,
- UINT8 *buf, int size, int force_pts)
+static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
{
AudioData *s = s1->priv_data;
int len, ret;
+ int size= pkt->size;
+ uint8_t *buf= pkt->data;
while (size > 0) {
len = AUDIO_BLOCK_SIZE - s->buffer_ptr;
if (ret > 0)
break;
if (ret < 0 && (errno != EAGAIN && errno != EINTR))
- return -EIO;
+ return AVERROR_IO;
}
s->buffer_ptr = 0;
}
ret = audio_open(s, 0, ap->device);
if (ret < 0) {
av_free(st);
- return -EIO;
+ return AVERROR_IO;
}
/* take real parameters */
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = s->codec_id;
- st->codec.sample_rate = s->sample_rate;
- st->codec.channels = s->channels;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_id = s->codec_id;
+ st->codec->sample_rate = s->sample_rate;
+ st->codec->channels = s->channels;
- av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
+ av_set_pts_info(st, 48, 1, 1000000); /* 48 bits pts in us */
return 0;
}
struct audio_buf_info abufi;
if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
+ return AVERROR_IO;
for(;;) {
+ struct timeval tv;
+ fd_set fds;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 30 * 1000; /* 30 msecs -- a bit shorter than 1 frame at 30fps */
+
+ FD_ZERO(&fds);
+ FD_SET(s->fd, &fds);
+
+ /* This will block until data is available or we get a timeout */
+ (void) select(s->fd + 1, &fds, 0, 0, &tv);
+
ret = read(s->fd, pkt->data, pkt->size);
if (ret > 0)
break;
if (ret == -1 && (errno == EAGAIN || errno == EINTR)) {
av_free_packet(pkt);
pkt->size = 0;
+ pkt->pts = av_gettime() & ((1LL << 48) - 1);
return 0;
}
if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) {
av_free_packet(pkt);
- return -EIO;
+ return AVERROR_IO;
}
}
pkt->size = ret;