2007-04-23 04:30:27 +02:00
|
|
|
// Copyright (c) 2007, Niels Martin Hansen
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file audio_player_pulse.cpp
|
|
|
|
/// @brief PulseAudio-based audio output
|
|
|
|
/// @ingroup audio_output
|
|
|
|
///
|
2007-04-23 04:30:27 +02:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-12-22 22:25:49 +01:00
|
|
|
#ifdef WITH_LIBPULSE
|
2008-01-21 21:57:20 +01:00
|
|
|
|
2012-03-20 00:31:33 +01:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include <wx/thread.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
|
2008-03-05 03:43:01 +01:00
|
|
|
#include "audio_player_pulse.h"
|
2007-04-23 04:30:27 +02:00
|
|
|
|
2012-01-08 02:33:39 +01:00
|
|
|
#include "audio_controller.h"
|
|
|
|
#include "include/aegisub/audio_provider.h"
|
|
|
|
#include "utils.h"
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2012-03-20 00:31:33 +01:00
|
|
|
#include <libaegisub/log.h>
|
|
|
|
|
2013-12-12 01:29:48 +01:00
|
|
|
PulseAudioPlayer::PulseAudioPlayer(AudioProvider *provider) : AudioPlayer(provider) {
|
2007-04-23 18:16:39 +02:00
|
|
|
// Initialise a mainloop
|
|
|
|
mainloop = pa_threaded_mainloop_new();
|
2012-03-20 00:31:33 +01:00
|
|
|
if (!mainloop)
|
2012-01-08 02:33:39 +01:00
|
|
|
throw agi::AudioPlayerOpenError("Failed to initialise PulseAudio threaded mainloop object", 0);
|
2012-03-20 00:31:33 +01:00
|
|
|
|
2007-04-23 18:16:39 +02:00
|
|
|
pa_threaded_mainloop_start(mainloop);
|
|
|
|
|
|
|
|
// Create context
|
|
|
|
context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "Aegisub");
|
|
|
|
if (!context) {
|
|
|
|
pa_threaded_mainloop_free(mainloop);
|
2012-01-08 02:33:39 +01:00
|
|
|
throw agi::AudioPlayerOpenError("Failed to create PulseAudio context", 0);
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
2007-04-23 18:16:39 +02:00
|
|
|
pa_context_set_state_callback(context, (pa_context_notify_cb_t)pa_context_notify, this);
|
|
|
|
|
|
|
|
// Connect the context
|
2012-11-13 17:51:01 +01:00
|
|
|
pa_context_connect(context, nullptr, PA_CONTEXT_NOAUTOSPAWN, nullptr);
|
2012-03-20 00:31:33 +01:00
|
|
|
|
2007-04-23 18:16:39 +02:00
|
|
|
// Wait for connection
|
|
|
|
while (true) {
|
|
|
|
context_notify.Wait();
|
|
|
|
if (cstate == PA_CONTEXT_READY) {
|
|
|
|
break;
|
|
|
|
} else if (cstate == PA_CONTEXT_FAILED) {
|
|
|
|
// eww
|
|
|
|
paerror = pa_context_errno(context);
|
|
|
|
pa_context_unref(context);
|
|
|
|
pa_threaded_mainloop_stop(mainloop);
|
|
|
|
pa_threaded_mainloop_free(mainloop);
|
2012-01-08 02:33:39 +01:00
|
|
|
throw agi::AudioPlayerOpenError(std::string("PulseAudio reported error: ") + pa_strerror(paerror), 0);
|
2007-04-23 18:16:39 +02:00
|
|
|
}
|
|
|
|
// otherwise loop once more
|
|
|
|
}
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2007-04-23 18:16:39 +02:00
|
|
|
// Set up stream
|
|
|
|
bpf = provider->GetChannels() * provider->GetBytesPerSample();
|
|
|
|
pa_sample_spec ss;
|
|
|
|
ss.format = PA_SAMPLE_S16LE; // FIXME
|
|
|
|
ss.rate = provider->GetSampleRate();
|
|
|
|
ss.channels = provider->GetChannels();
|
|
|
|
pa_channel_map map;
|
|
|
|
pa_channel_map_init_auto(&map, ss.channels, PA_CHANNEL_MAP_DEFAULT);
|
2012-03-20 00:31:33 +01:00
|
|
|
|
2007-04-23 18:16:39 +02:00
|
|
|
stream = pa_stream_new(context, "Sound", &ss, &map);
|
|
|
|
if (!stream) {
|
|
|
|
// argh!
|
|
|
|
pa_context_disconnect(context);
|
|
|
|
pa_context_unref(context);
|
|
|
|
pa_threaded_mainloop_stop(mainloop);
|
|
|
|
pa_threaded_mainloop_free(mainloop);
|
2012-01-08 02:33:39 +01:00
|
|
|
throw agi::AudioPlayerOpenError("PulseAudio could not create stream", 0);
|
2007-04-23 18:16:39 +02:00
|
|
|
}
|
|
|
|
pa_stream_set_state_callback(stream, (pa_stream_notify_cb_t)pa_stream_notify, this);
|
|
|
|
pa_stream_set_write_callback(stream, (pa_stream_request_cb_t)pa_stream_write, this);
|
|
|
|
|
2007-07-18 15:46:38 +02:00
|
|
|
// Connect stream
|
2012-11-13 17:51:01 +01:00
|
|
|
paerror = pa_stream_connect_playback(stream, nullptr, nullptr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_NOT_MONOTONOUS|PA_STREAM_AUTO_TIMING_UPDATE), nullptr, nullptr);
|
2007-04-23 18:16:39 +02:00
|
|
|
if (paerror) {
|
2012-03-20 00:31:33 +01:00
|
|
|
LOG_E("audio/player/pulse") << "Stream connection failed: " << pa_strerror(paerror) << "(" << paerror << ")";
|
2012-01-08 02:33:39 +01:00
|
|
|
throw agi::AudioPlayerOpenError(std::string("PulseAudio reported error: ") + pa_strerror(paerror), 0);
|
2007-04-23 18:16:39 +02:00
|
|
|
}
|
|
|
|
while (true) {
|
|
|
|
stream_notify.Wait();
|
|
|
|
if (sstate == PA_STREAM_READY) {
|
|
|
|
break;
|
|
|
|
} else if (sstate == PA_STREAM_FAILED) {
|
2007-04-23 22:26:39 +02:00
|
|
|
paerror = pa_context_errno(context);
|
2012-03-20 00:31:33 +01:00
|
|
|
LOG_E("audio/player/pulse") << "Stream connection failed: " << pa_strerror(paerror) << "(" << paerror << ")";
|
2012-01-08 02:33:39 +01:00
|
|
|
throw agi::AudioPlayerOpenError("PulseAudio player: Something went wrong connecting the stream", 0);
|
2007-04-23 18:16:39 +02:00
|
|
|
}
|
|
|
|
}
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
2012-03-20 00:31:33 +01:00
|
|
|
PulseAudioPlayer::~PulseAudioPlayer()
|
2007-04-23 18:16:39 +02:00
|
|
|
{
|
|
|
|
if (is_playing) Stop();
|
|
|
|
|
|
|
|
// Hope for the best and just do things as quickly as possible
|
|
|
|
pa_stream_disconnect(stream);
|
|
|
|
pa_stream_unref(stream);
|
|
|
|
pa_context_disconnect(context);
|
|
|
|
pa_context_unref(context);
|
|
|
|
pa_threaded_mainloop_stop(mainloop);
|
|
|
|
pa_threaded_mainloop_free(mainloop);
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
2007-08-31 16:11:35 +02:00
|
|
|
void PulseAudioPlayer::Play(int64_t start,int64_t count)
|
2007-04-23 18:16:39 +02:00
|
|
|
{
|
2007-04-23 22:26:39 +02:00
|
|
|
if (is_playing) {
|
|
|
|
// If we're already playing, do a quick "reset"
|
|
|
|
is_playing = false;
|
|
|
|
|
2007-04-23 22:58:21 +02:00
|
|
|
pa_threaded_mainloop_lock(mainloop);
|
2007-04-23 22:26:39 +02:00
|
|
|
pa_operation *op = pa_stream_flush(stream, (pa_stream_success_cb_t)pa_stream_success, this);
|
2007-04-23 22:58:21 +02:00
|
|
|
pa_threaded_mainloop_unlock(mainloop);
|
2007-04-23 22:26:39 +02:00
|
|
|
stream_success.Wait();
|
|
|
|
pa_operation_unref(op);
|
|
|
|
if (!stream_success_val) {
|
|
|
|
paerror = pa_context_errno(context);
|
2012-03-20 00:31:33 +01:00
|
|
|
LOG_E("audio/player/pulse") << "Error flushing stream: " << pa_strerror(paerror) << "(" << paerror << ")";
|
2007-04-23 22:26:39 +02:00
|
|
|
}
|
|
|
|
}
|
2007-04-23 18:16:39 +02:00
|
|
|
|
|
|
|
start_frame = start;
|
|
|
|
cur_frame = start;
|
|
|
|
end_frame = start + count;
|
|
|
|
|
|
|
|
is_playing = true;
|
2007-04-23 04:30:27 +02:00
|
|
|
|
2007-04-23 19:34:39 +02:00
|
|
|
play_start_time = 0;
|
2007-04-23 22:58:21 +02:00
|
|
|
pa_threaded_mainloop_lock(mainloop);
|
2009-09-02 11:00:03 +02:00
|
|
|
paerror = pa_stream_get_time(stream, (pa_usec_t*) &play_start_time);
|
2007-04-23 22:58:21 +02:00
|
|
|
pa_threaded_mainloop_unlock(mainloop);
|
2012-03-20 00:31:33 +01:00
|
|
|
if (paerror)
|
|
|
|
LOG_E("audio/player/pulse") << "Error getting stream time: " << pa_strerror(paerror) << "(" << paerror << ")";
|
2007-04-23 19:34:39 +02:00
|
|
|
|
2007-04-23 18:16:39 +02:00
|
|
|
PulseAudioPlayer::pa_stream_write(stream, pa_stream_writable_size(stream), this);
|
|
|
|
|
2007-04-23 22:58:21 +02:00
|
|
|
pa_threaded_mainloop_lock(mainloop);
|
2007-04-23 18:16:39 +02:00
|
|
|
pa_operation *op = pa_stream_trigger(stream, (pa_stream_success_cb_t)pa_stream_success, this);
|
2007-04-23 22:58:21 +02:00
|
|
|
pa_threaded_mainloop_unlock(mainloop);
|
2007-04-23 18:16:39 +02:00
|
|
|
stream_success.Wait();
|
|
|
|
pa_operation_unref(op);
|
2007-04-23 22:26:39 +02:00
|
|
|
if (!stream_success_val) {
|
|
|
|
paerror = pa_context_errno(context);
|
2012-03-20 00:31:33 +01:00
|
|
|
LOG_E("audio/player/pulse") << "Error triggering stream: " << pa_strerror(paerror) << "(" << paerror << ")";
|
2007-04-23 22:26:39 +02:00
|
|
|
}
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 06:05:44 +02:00
|
|
|
void PulseAudioPlayer::Stop()
|
2007-04-23 18:16:39 +02:00
|
|
|
{
|
|
|
|
if (!is_playing) return;
|
|
|
|
|
|
|
|
is_playing = false;
|
|
|
|
|
|
|
|
start_frame = 0;
|
|
|
|
cur_frame = 0;
|
|
|
|
end_frame = 0;
|
|
|
|
|
|
|
|
// Flush the stream of data
|
2007-04-23 22:58:21 +02:00
|
|
|
pa_threaded_mainloop_lock(mainloop);
|
2007-04-23 19:34:39 +02:00
|
|
|
pa_operation *op = pa_stream_flush(stream, (pa_stream_success_cb_t)pa_stream_success, this);
|
2007-04-23 22:58:21 +02:00
|
|
|
pa_threaded_mainloop_unlock(mainloop);
|
2007-04-23 18:16:39 +02:00
|
|
|
stream_success.Wait();
|
|
|
|
pa_operation_unref(op);
|
2007-04-23 22:26:39 +02:00
|
|
|
if (!stream_success_val) {
|
|
|
|
paerror = pa_context_errno(context);
|
2012-03-20 00:31:33 +01:00
|
|
|
LOG_E("audio/player/pulse") << "Error flushing stream: " << pa_strerror(paerror) << "(" << paerror << ")";
|
2007-04-23 22:26:39 +02:00
|
|
|
}
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
2007-08-31 16:11:35 +02:00
|
|
|
void PulseAudioPlayer::SetEndPosition(int64_t pos)
|
2007-04-23 18:16:39 +02:00
|
|
|
{
|
|
|
|
end_frame = pos;
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
2007-08-31 16:11:35 +02:00
|
|
|
int64_t PulseAudioPlayer::GetCurrentPosition()
|
2007-04-23 04:30:27 +02:00
|
|
|
{
|
2007-04-23 19:34:39 +02:00
|
|
|
if (!is_playing) return 0;
|
|
|
|
|
2007-05-11 00:39:17 +02:00
|
|
|
// FIXME: this should be based on not duration played but actual sample being heard
|
|
|
|
// (during vidoeo playback, cur_frame might get changed to resync)
|
|
|
|
|
2007-04-23 19:34:39 +02:00
|
|
|
// Calculation duration we have played, in microseconds
|
|
|
|
pa_usec_t play_cur_time;
|
|
|
|
pa_stream_get_time(stream, &play_cur_time);
|
|
|
|
pa_usec_t playtime = play_cur_time - play_start_time;
|
|
|
|
|
|
|
|
return start_frame + playtime * provider->GetSampleRate() / (1000*1000);
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Called by PA to notify about contetxt operation completion
|
2007-04-23 18:16:39 +02:00
|
|
|
void PulseAudioPlayer::pa_context_success(pa_context *c, int success, PulseAudioPlayer *thread)
|
2007-04-23 04:30:27 +02:00
|
|
|
{
|
2007-04-23 18:16:39 +02:00
|
|
|
thread->context_success_val = success;
|
|
|
|
thread->context_success.Post();
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Called by PA to notify about other context-related stuff
|
2007-04-23 18:16:39 +02:00
|
|
|
void PulseAudioPlayer::pa_context_notify(pa_context *c, PulseAudioPlayer *thread)
|
2007-04-23 04:30:27 +02:00
|
|
|
{
|
2007-04-23 18:16:39 +02:00
|
|
|
thread->cstate = pa_context_get_state(thread->context);
|
|
|
|
thread->context_notify.Post();
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Called by PA when an operation completes
|
2007-04-23 18:16:39 +02:00
|
|
|
void PulseAudioPlayer::pa_stream_success(pa_stream *p, int success, PulseAudioPlayer *thread)
|
2007-04-23 04:30:27 +02:00
|
|
|
{
|
2007-04-23 18:16:39 +02:00
|
|
|
thread->stream_success_val = success;
|
|
|
|
thread->stream_success.Post();
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Called by PA to request more data (and other things?)
|
2007-04-23 18:16:39 +02:00
|
|
|
void PulseAudioPlayer::pa_stream_write(pa_stream *p, size_t length, PulseAudioPlayer *thread)
|
2007-04-23 04:30:27 +02:00
|
|
|
{
|
2007-04-23 18:16:39 +02:00
|
|
|
if (!thread->is_playing) return;
|
2007-04-23 22:58:21 +02:00
|
|
|
|
|
|
|
if (thread->cur_frame >= thread->end_frame + thread->provider->GetSampleRate()) {
|
|
|
|
// More than a second past end of stream
|
2007-04-23 18:16:39 +02:00
|
|
|
thread->is_playing = false;
|
2012-11-13 17:51:01 +01:00
|
|
|
pa_operation *op = pa_stream_drain(p, nullptr, nullptr);
|
2007-04-23 19:34:39 +02:00
|
|
|
pa_operation_unref(op);
|
2007-04-23 18:16:39 +02:00
|
|
|
return;
|
2007-04-23 22:58:21 +02:00
|
|
|
|
|
|
|
} else if (thread->cur_frame >= thread->end_frame) {
|
|
|
|
// Past end of stream, but not a full second, add some silence
|
|
|
|
void *buf = calloc(length, 1);
|
|
|
|
::pa_stream_write(p, buf, length, free, 0, PA_SEEK_RELATIVE);
|
|
|
|
thread->cur_frame += length / thread->bpf;
|
|
|
|
return;
|
2007-04-23 18:16:39 +02:00
|
|
|
}
|
2007-04-23 04:30:27 +02:00
|
|
|
|
2007-04-23 18:16:39 +02:00
|
|
|
unsigned long bpf = thread->bpf;
|
|
|
|
unsigned long frames = length / thread->bpf;
|
|
|
|
unsigned long maxframes = thread->end_frame - thread->cur_frame;
|
|
|
|
if (frames > maxframes) frames = maxframes;
|
|
|
|
void *buf = malloc(frames * bpf);
|
|
|
|
thread->provider->GetAudioWithVolume(buf, thread->cur_frame, frames, thread->volume);
|
|
|
|
::pa_stream_write(p, buf, frames*bpf, free, 0, PA_SEEK_RELATIVE);
|
|
|
|
thread->cur_frame += frames;
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Called by PA to notify about other stuff
|
2007-04-23 18:16:39 +02:00
|
|
|
void PulseAudioPlayer::pa_stream_notify(pa_stream *p, PulseAudioPlayer *thread)
|
2007-04-23 04:30:27 +02:00
|
|
|
{
|
2007-04-23 18:16:39 +02:00
|
|
|
thread->sstate = pa_stream_get_state(thread->stream);
|
|
|
|
thread->stream_notify.Post();
|
2007-04-23 04:30:27 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:25:49 +01:00
|
|
|
#endif // WITH_LIBPULSE
|