2013-09-30 19:37:13 -07:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-10-14 04:21:15 -07:00
|
|
|
#pragma once
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
#include "../util/c99defs.h"
|
|
|
|
#include "media-io.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Base audio output component. Use this to create an audio output track
|
|
|
|
* for the media.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct audio_output;
|
2013-10-24 00:57:55 -07:00
|
|
|
struct audio_line;
|
2013-09-30 19:37:13 -07:00
|
|
|
typedef struct audio_output *audio_t;
|
2013-10-24 00:57:55 -07:00
|
|
|
typedef struct audio_line *audio_line_t;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2013-10-30 17:07:01 -07:00
|
|
|
enum audio_format {
|
2013-09-30 19:37:13 -07:00
|
|
|
AUDIO_FORMAT_UNKNOWN,
|
2013-10-30 17:07:01 -07:00
|
|
|
AUDIO_FORMAT_U8BIT,
|
2013-09-30 19:37:13 -07:00
|
|
|
AUDIO_FORMAT_16BIT,
|
|
|
|
AUDIO_FORMAT_32BIT,
|
|
|
|
AUDIO_FORMAT_FLOAT,
|
|
|
|
};
|
|
|
|
|
2013-10-30 17:07:01 -07:00
|
|
|
enum speaker_layout {
|
2013-09-30 19:37:13 -07:00
|
|
|
SPEAKERS_UNKNOWN,
|
|
|
|
SPEAKERS_MONO,
|
|
|
|
SPEAKERS_STEREO,
|
|
|
|
SPEAKERS_2POINT1,
|
|
|
|
SPEAKERS_QUAD,
|
|
|
|
SPEAKERS_4POINT1,
|
|
|
|
SPEAKERS_5POINT1,
|
|
|
|
SPEAKERS_5POINT1_SURROUND,
|
|
|
|
SPEAKERS_7POINT1,
|
|
|
|
SPEAKERS_7POINT1_SURROUND,
|
|
|
|
SPEAKERS_SURROUND,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct audio_data {
|
2013-10-30 17:07:01 -07:00
|
|
|
const void *data;
|
|
|
|
uint32_t frames;
|
|
|
|
uint64_t timestamp;
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct audio_info {
|
2013-10-30 17:07:01 -07:00
|
|
|
const char *name;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2013-10-30 17:07:01 -07:00
|
|
|
uint32_t samples_per_sec;
|
2013-10-31 10:28:47 -07:00
|
|
|
enum audio_format format;
|
2013-10-30 17:07:01 -07:00
|
|
|
enum speaker_layout speakers;
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2013-10-30 17:07:01 -07:00
|
|
|
static inline uint32_t get_audio_channels(enum speaker_layout speakers)
|
2013-10-24 00:57:55 -07:00
|
|
|
{
|
|
|
|
switch (speakers) {
|
|
|
|
case SPEAKERS_MONO: return 1;
|
|
|
|
case SPEAKERS_STEREO: return 2;
|
|
|
|
case SPEAKERS_2POINT1: return 3;
|
|
|
|
case SPEAKERS_SURROUND:
|
|
|
|
case SPEAKERS_QUAD: return 4;
|
|
|
|
case SPEAKERS_4POINT1: return 5;
|
|
|
|
case SPEAKERS_5POINT1:
|
|
|
|
case SPEAKERS_5POINT1_SURROUND: return 6;
|
|
|
|
case SPEAKERS_7POINT1: return 8;
|
|
|
|
case SPEAKERS_7POINT1_SURROUND: return 8;
|
|
|
|
case SPEAKERS_UNKNOWN: return 0;
|
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return 0;
|
2013-10-24 00:57:55 -07:00
|
|
|
}
|
|
|
|
|
2013-10-30 17:07:01 -07:00
|
|
|
static inline size_t get_audio_bytes_per_channel(enum audio_format type)
|
2013-10-24 00:57:55 -07:00
|
|
|
{
|
|
|
|
switch (type) {
|
2013-10-30 17:07:01 -07:00
|
|
|
case AUDIO_FORMAT_U8BIT: return 1;
|
2013-10-24 00:57:55 -07:00
|
|
|
case AUDIO_FORMAT_16BIT: return 2;
|
|
|
|
case AUDIO_FORMAT_FLOAT:
|
|
|
|
case AUDIO_FORMAT_32BIT: return 4;
|
|
|
|
case AUDIO_FORMAT_UNKNOWN: return 0;
|
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return 0;
|
2013-10-24 00:57:55 -07:00
|
|
|
}
|
|
|
|
|
2013-10-30 17:07:01 -07:00
|
|
|
static inline size_t get_audio_size(enum audio_format type,
|
|
|
|
enum speaker_layout speakers, uint32_t frames)
|
2013-10-24 00:57:55 -07:00
|
|
|
{
|
|
|
|
return get_audio_channels(speakers) *
|
|
|
|
get_audio_bytes_per_channel(type) *
|
|
|
|
frames;
|
|
|
|
}
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
#define AUDIO_OUTPUT_SUCCESS 0
|
|
|
|
#define AUDIO_OUTPUT_INVALIDPARAM -1
|
|
|
|
#define AUDIO_OUTPUT_FAIL -2
|
|
|
|
|
|
|
|
EXPORT int audio_output_open(audio_t *audio, media_t media,
|
|
|
|
struct audio_info *info);
|
2013-10-24 00:57:55 -07:00
|
|
|
EXPORT audio_line_t audio_output_createline(audio_t audio);
|
|
|
|
EXPORT size_t audio_output_blocksize(audio_t audio);
|
|
|
|
EXPORT const struct audio_info *audio_output_getinfo(audio_t audio);
|
2013-09-30 19:37:13 -07:00
|
|
|
EXPORT void audio_output_close(audio_t audio);
|
|
|
|
|
2013-10-24 00:57:55 -07:00
|
|
|
EXPORT void audio_line_destroy(audio_line_t line);
|
|
|
|
EXPORT void audio_line_output(audio_line_t line, const struct audio_data *data);
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|