Commit a614f892 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge remote-tracking branch 'lukaszmluki/master'

* lukaszmluki/master:
  lavd/pulse_audio_enc: implement pause messages
  lavd/pulse_audio_enc: implement volume messages
  lavd/avdevice: add volume messages
  lavd/pulse_audio_enc: add buffer fullness messages
  lavd/pulse_audio_enc: add nonblocking mode
  lavd/pulse_audio_enc: replace simple API with async API
  lavd/pulse_audio_enc: cosmetics
  lavd/pulse_audio_common: add context helper functions
  lavd/pulse_audio_common: rename variables and enums
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 27998451 35bf7a49
......@@ -154,6 +154,41 @@ enum AVAppToDevMessageType {
AV_APP_TO_DEV_PAUSE = MKBETAG('P', 'A', 'U', ' '),
AV_APP_TO_DEV_PLAY = MKBETAG('P', 'L', 'A', 'Y'),
AV_APP_TO_DEV_TOGGLE_PAUSE = MKBETAG('P', 'A', 'U', 'T'),
/**
* Volume control message.
*
* Set volume level. It may be device-dependent if volume
* is changed per stream or system wide. Per stream volume
* change is expected when possible.
*
* data: double: new volume with range of 0.0 - 1.0.
*/
AV_APP_TO_DEV_SET_VOLUME = MKBETAG('S', 'V', 'O', 'L'),
/**
* Mute control messages.
*
* Change mute state. It may be device-dependent if mute status
* is changed per stream or system wide. Per stream mute status
* change is expected when possible.
*
* data: NULL.
*/
AV_APP_TO_DEV_MUTE = MKBETAG(' ', 'M', 'U', 'T'),
AV_APP_TO_DEV_UNMUTE = MKBETAG('U', 'M', 'U', 'T'),
AV_APP_TO_DEV_TOGGLE_MUTE = MKBETAG('T', 'M', 'U', 'T'),
/**
* Get volume/mute messages.
*
* Force the device to send AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED or
* AV_DEV_TO_APP_MUTE_STATE_CHANGED command respectively.
*
* data: NULL.
*/
AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'),
AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'),
};
/**
......@@ -237,6 +272,24 @@ enum AVDevToAppMessageType {
*/
AV_DEV_TO_APP_BUFFER_READABLE = MKBETAG('B','R','D',' '),
AV_DEV_TO_APP_BUFFER_WRITABLE = MKBETAG('B','W','R',' '),
/**
* Mute state change message.
*
* Device informs that mute state has changed.
*
* data: int: 0 for not muted state, non-zero for muted state.
*/
AV_DEV_TO_APP_MUTE_STATE_CHANGED = MKBETAG('C','M','U','T'),
/**
* Volume level change message.
*
* Device informs that volume level has changed.
*
* data: double: new volume with range of 0.0 - 1.0.
*/
AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED = MKBETAG('C','V','O','L'),
};
/**
......
......@@ -24,6 +24,7 @@
#include "libavutil/attributes.h"
#include "libavutil/avstring.h"
#include "libavutil/mem.h"
#include "libavutil/avassert.h"
pa_sample_format_t av_cold ff_codec_id_to_pulse_format(enum AVCodecID codec_id)
{
......@@ -43,10 +44,10 @@ pa_sample_format_t av_cold ff_codec_id_to_pulse_format(enum AVCodecID codec_id)
}
}
enum PulseAudioLoopState {
PA_LOOP_INITIALIZING,
PA_LOOP_READY,
PA_LOOP_FINISHED
enum PulseAudioContextState {
PULSE_CONTEXT_INITIALIZING,
PULSE_CONTEXT_READY,
PULSE_CONTEXT_FINISHED
};
typedef struct PulseAudioDeviceList {
......@@ -58,21 +59,79 @@ typedef struct PulseAudioDeviceList {
static void pa_state_cb(pa_context *c, void *userdata)
{
enum PulseAudioLoopState *loop_status = userdata;
enum PulseAudioContextState *context_state = userdata;
switch (pa_context_get_state(c)) {
case PA_CONTEXT_FAILED:
case PA_CONTEXT_TERMINATED:
*loop_status = PA_LOOP_FINISHED;
*context_state = PULSE_CONTEXT_FINISHED;
break;
case PA_CONTEXT_READY:
*loop_status = PA_LOOP_READY;
*context_state = PULSE_CONTEXT_READY;
break;
default:
break;
}
}
void ff_pulse_audio_disconnect_context(pa_mainloop **pa_ml, pa_context **pa_ctx)
{
av_assert0(pa_ml);
av_assert0(pa_ctx);
if (*pa_ctx) {
pa_context_set_state_callback(*pa_ctx, NULL, NULL);
pa_context_disconnect(*pa_ctx);
pa_context_unref(*pa_ctx);
}
if (*pa_ml)
pa_mainloop_free(*pa_ml);
*pa_ml = NULL;
*pa_ctx = NULL;
}
int ff_pulse_audio_connect_context(pa_mainloop **pa_ml, pa_context **pa_ctx,
const char *server, const char *description)
{
int ret;
pa_mainloop_api *pa_mlapi = NULL;
enum PulseAudioContextState context_state = PULSE_CONTEXT_INITIALIZING;
av_assert0(pa_ml);
av_assert0(pa_ctx);
*pa_ml = NULL;
*pa_ctx = NULL;
if (!(*pa_ml = pa_mainloop_new()))
return AVERROR(ENOMEM);
if (!(pa_mlapi = pa_mainloop_get_api(*pa_ml))) {
ret = AVERROR_EXTERNAL;
goto fail;
}
if (!(*pa_ctx = pa_context_new(pa_mlapi, description))) {
ret = AVERROR(ENOMEM);
goto fail;
}
pa_context_set_state_callback(*pa_ctx, pa_state_cb, &context_state);
if (pa_context_connect(*pa_ctx, server, 0, NULL) < 0) {
ret = AVERROR_EXTERNAL;
goto fail;
}
while (context_state == PULSE_CONTEXT_INITIALIZING)
pa_mainloop_iterate(*pa_ml, 1, NULL);
if (context_state == PULSE_CONTEXT_FINISHED) {
ret = AVERROR_EXTERNAL;
goto fail;
}
return 0;
fail:
ff_pulse_audio_disconnect_context(pa_ml, pa_ctx);
return ret;
}
static void pulse_add_detected_device(PulseAudioDeviceList *info,
const char *name, const char *description)
{
......@@ -138,11 +197,9 @@ static void pulse_server_info_cb(pa_context *c, const pa_server_info *i, void *u
int ff_pulse_audio_get_devices(AVDeviceInfoList *devices, const char *server, int output)
{
pa_mainloop *pa_ml = NULL;
pa_mainloop_api *pa_mlapi = NULL;
pa_operation *pa_op = NULL;
pa_context *pa_ctx = NULL;
enum pa_operation_state op_state;
enum PulseAudioLoopState loop_state = PA_LOOP_INITIALIZING;
PulseAudioDeviceList dev_list = { 0 };
int i;
......@@ -152,28 +209,9 @@ int ff_pulse_audio_get_devices(AVDeviceInfoList *devices, const char *server, in
return AVERROR(EINVAL);
devices->nb_devices = 0;
devices->devices = NULL;
if (!(pa_ml = pa_mainloop_new()))
return AVERROR(ENOMEM);
if (!(pa_mlapi = pa_mainloop_get_api(pa_ml))) {
dev_list.error_code = AVERROR_EXTERNAL;
goto fail;
}
if (!(pa_ctx = pa_context_new(pa_mlapi, "Query devices"))) {
dev_list.error_code = AVERROR(ENOMEM);
goto fail;
}
pa_context_set_state_callback(pa_ctx, pa_state_cb, &loop_state);
if (pa_context_connect(pa_ctx, server, 0, NULL) < 0) {
dev_list.error_code = AVERROR_EXTERNAL;
goto fail;
}
while (loop_state == PA_LOOP_INITIALIZING)
pa_mainloop_iterate(pa_ml, 1, NULL);
if (loop_state == PA_LOOP_FINISHED) {
dev_list.error_code = AVERROR_EXTERNAL;
if ((dev_list.error_code = ff_pulse_audio_connect_context(&pa_ml, &pa_ctx, server, "Query devices")) < 0)
goto fail;
}
if (output)
pa_op = pa_context_get_sink_info_list(pa_ctx, pulse_audio_sink_device_cb, &dev_list);
......@@ -206,11 +244,6 @@ int ff_pulse_audio_get_devices(AVDeviceInfoList *devices, const char *server, in
fail:
av_free(dev_list.default_device);
if(pa_ctx)
pa_context_disconnect(pa_ctx);
if (pa_ctx)
pa_context_unref(pa_ctx);
if (pa_ml)
pa_mainloop_free(pa_ml);
ff_pulse_audio_disconnect_context(&pa_ml, &pa_ctx);
return dev_list.error_code;
}
......@@ -30,4 +30,9 @@ pa_sample_format_t ff_codec_id_to_pulse_format(enum AVCodecID codec_id);
int ff_pulse_audio_get_devices(AVDeviceInfoList *devices, const char *server, int output);
int ff_pulse_audio_connect_context(pa_mainloop **pa_ml, pa_context **pa_ctx,
const char *server, const char *description);
void ff_pulse_audio_disconnect_context(pa_mainloop **pa_ml, pa_context **pa_ctx);
#endif /* AVDEVICE_PULSE_AUDIO_COMMON_H */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment