* BeOS audio play interface
* Copyright (c) 2000, 2001 Fabrice Bellard.
*
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <signal.h>
#ifdef HAVE_BSOUNDRECORDER
#include <SoundRecorder.h>
+using namespace BPrivate::Media::Experimental;
#endif
/* enable performance checks */
//#define LATENCY_CHECK
#define AUDIO_BLOCK_SIZE 4096
-//#define AUDIO_BLOCK_SIZE 2048
#define AUDIO_BLOCK_COUNT 8
#define AUDIO_BUFFER_SIZE (AUDIO_BLOCK_SIZE*AUDIO_BLOCK_COUNT)
int input_index;
sem_id output_sem;
int output_index;
- int queued;
BSoundPlayer *player;
#ifdef HAVE_BSOUNDRECORDER
BSoundRecorder *recorder;
#ifndef HAVE_BSOUNDRECORDER
if (!is_output)
- return -EIO; /* not for now */
+ return AVERROR(EIO); /* not for now */
#endif
s->input_sem = create_sem(AUDIO_BUFFER_SIZE, "ffmpeg_ringbuffer_input");
-// s->input_sem = create_sem(AUDIO_BLOCK_SIZE, "ffmpeg_ringbuffer_input");
if (s->input_sem < B_OK)
- return -EIO;
+ return AVERROR(EIO);
s->output_sem = create_sem(0, "ffmpeg_ringbuffer_output");
if (s->output_sem < B_OK) {
delete_sem(s->input_sem);
- return -EIO;
+ return AVERROR(EIO);
}
s->input_index = 0;
s->output_index = 0;
- s->queued = 0;
create_bapp_if_needed();
s->frame_size = AUDIO_BLOCK_SIZE;
/* bump up the priority (avoid realtime though) */
delete_sem(s->input_sem);
if (s->output_sem)
delete_sem(s->output_sem);
- return -EIO;
+ return AVERROR(EIO);
}
s->codec_id = (iformat.byte_order == B_MEDIA_LITTLE_ENDIAN)?CODEC_ID_PCM_S16LE:CODEC_ID_PCM_S16BE;
s->channels = iformat.channel_count;
delete_sem(s->input_sem);
if (s->output_sem)
delete_sem(s->output_sem);
- return -EIO;
+ return AVERROR(EIO);
}
s->player->SetCookie(s);
s->player->SetVolume(1.0);
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(EIO);
return 0;
}
static int audio_write_packet(AVFormatContext *s1, int stream_index,
- uint8_t *buf, int size, int force_pts)
+ const uint8_t *buf, int size, int64_t force_pts)
{
AudioData *s = (AudioData *)s1->priv_data;
int len, ret;
int amount;
len = MIN(size, AUDIO_BLOCK_SIZE);
if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK)
- return -EIO;
+ return AVERROR(EIO);
amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
memcpy(&s->buffer[s->input_index], buf, amount);
s->input_index += amount;
st = av_new_stream(s1, 0);
if (!st) {
- return -ENOMEM;
+ return AVERROR(ENOMEM);
}
s->sample_rate = ap->sample_rate;
s->channels = ap->channels;
- ret = audio_open(s, 0, ap->device);
+ ret = audio_open(s, 0, s1->filename);
if (ret < 0) {
av_free(st);
- return -EIO;
+ return AVERROR(EIO);
}
/* 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;
return 0;
av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
}
status_t err;
if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
+ return AVERROR(EIO);
buf = (unsigned char *)pkt->data;
size = pkt->size;
while (size > 0) {
while ((err=acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL)) == B_INTERRUPTED);
if (err < B_OK) {
av_free_packet(pkt);
- return -EIO;
+ return AVERROR(EIO);
}
amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
memcpy(buf, &s->buffer[s->output_index], amount);
return 0;
}
-static AVInputFormat audio_in_format = {
+static AVInputFormat audio_demuxer = {
"audio_device",
"audio grab and output",
sizeof(AudioData),
AVFMT_NOFILE,
};
-AVOutputFormat audio_out_format = {
+AVOutputFormat audio_muxer = {
"audio_device",
"audio grab and output",
"",
int audio_init(void)
{
main_thid = find_thread(NULL);
- av_register_input_format(&audio_in_format);
- av_register_output_format(&audio_out_format);
+ av_register_input_format(&audio_demuxer);
+ av_register_output_format(&audio_muxer);
return 0;
}