Make video and audio providers throw typed exceptions.

Don't display error messages and try other providers when the user
cancels loading a file.

Remove files from the MRU lists if they can't be found.

Closes #717.

Originally committed to SVN as r4717.
This commit is contained in:
Thomas Goyne 2010-08-02 06:32:01 +00:00
parent 71fb04cd29
commit c10e9e3a5b
65 changed files with 574 additions and 1279 deletions

View file

@ -131,16 +131,13 @@ namespace Endian {
#ifndef HAVE_DYNAMIC_ENDIAN
// Regular, fast, templatized conditional reversing
template <class T>
/// @brief DOCME
/// @param val
/// @return
///
template <class T>
inline T LittleToMachine(T val)
{
#ifdef HAVE_BIG_ENDIAN
@ -152,12 +149,11 @@ namespace Endian {
#endif
}
template <class T>
/// @brief DOCME
/// @param val
/// @return
///
template <class T>
inline T BigToMachine(T val)
{
#ifdef HAVE_LITTLE_ENDIAN
@ -169,12 +165,11 @@ namespace Endian {
#endif
}
template <class T>
/// @brief DOCME
/// @param val
/// @return
///
template <class T>
inline T MachineToLittle(T val)
{
#ifdef HAVE_BIG_ENDIAN
@ -186,12 +181,11 @@ namespace Endian {
#endif
}
template <class T>
/// @brief DOCME
/// @param val
/// @return
///
template <class T>
inline T MachineToBig(T val)
{
#ifdef HAVE_LITTLE_ENDIAN
@ -203,10 +197,8 @@ namespace Endian {
#endif
}
#else // HAVE_DYNAMIC_ENDIAN
// Dynamic endianness handling
// Exploit that bit-shifting operations always can put bytes into
@ -216,13 +208,11 @@ namespace Endian {
// the endianness of the machine we are on, but it's the same
// code for any platform!
// Unions to pack together ints and get their physical bytes
/// DOCME
union bytes16 {
/// DOCME
uint8_t byte[2];
@ -232,7 +222,6 @@ namespace Endian {
/// DOCME
union bytes32 {
/// DOCME
uint8_t byte[4];
@ -242,7 +231,6 @@ namespace Endian {
/// DOCME
union bytes64 {
/// DOCME
uint8_t byte[8];
@ -250,7 +238,6 @@ namespace Endian {
uint64_t word;
};
// 16 bit words
@ -456,8 +443,5 @@ namespace Endian {
uint64_t(pack.byte[0]);
}
#endif
};

View file

@ -50,7 +50,5 @@
// So unless we protect it by this, it gets included twice during production of precompiled
// headers, which can cause problems with local includes.
#ifndef AGI_PRE
#include "config.h"
#include "agi_pre.h"
#endif

View file

@ -43,7 +43,7 @@
#ifndef AGI_PRE_H
/// @brief Inclusion guard.
/// @todo Why is this even nessicary? GCC seems to include agi_pre.h twice for no reason.
/// @todo Why is this even necessary? GCC seems to include agi_pre.h twice for no reason.
#define AGI_PRE_H
// C++ only

View file

@ -34,12 +34,8 @@
/// @ingroup export
///
#pragma once
///////////
// Headers
#ifndef AGI_PRE
#include <list>
#include <memory>
@ -48,21 +44,14 @@
#include <wx/window.h>
#endif
//////////////
// Prototypes
class AssFile;
class AssExportFilter;
class DialogExport;
class AssExporter;
/// DOCME
typedef std::list<AssExportFilter*> FilterList;
/// DOCME
/// @class AssExportFilterChain
/// @brief DOCME
@ -80,7 +69,6 @@ private:
/// DOCME
FilterList Unprepared;
/// DOCME
static std::auto_ptr<AssExportFilterChain> instance;
static FilterList *GetFilterList();
@ -90,8 +78,6 @@ public:
static void PrepareFilters();
};
/// DOCME
/// @class AssExportFilter
/// @brief DOCME
@ -139,4 +125,3 @@ public:
virtual void LoadSettings(bool IsDefault); // Config dialog is done - extract data now.
};

View file

@ -36,16 +36,11 @@
#include "config.h"
#ifndef AGI_PRE
#include <memory>
#endif
#include "ass_export_filter.h"
#include "ass_exporter.h"
#include "ass_file.h"
#include "frame_main.h"
/// @brief Constructor
/// @param subs
///
@ -54,15 +49,11 @@ AssExporter::AssExporter (AssFile *subs) {
IsDefault = true;
}
/// @brief Destructor
///
AssExporter::~AssExporter () {
}
/// @brief Draw control settings
/// @param parent
/// @param AddTo
@ -90,8 +81,6 @@ void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
}
}
/// @brief Add filter to chain
/// @param name
///
@ -113,8 +102,6 @@ void AssExporter::AddFilter(wxString name) {
Filters.push_back(filter);
}
/// @brief Adds all autoexporting filters to chain
///
void AssExporter::AddAutoFilters() {
@ -127,8 +114,6 @@ void AssExporter::AddAutoFilters() {
}
}
/// @brief Get name of all filters
/// @return
///
@ -142,8 +127,6 @@ wxArrayString AssExporter::GetAllFilterNames() {
return names;
}
/// @brief Transform for export
/// @param export_dialog
/// @return
@ -162,8 +145,6 @@ AssFile *AssExporter::ExportTransform(wxWindow *export_dialog) {
return Subs;
}
/// @brief Export
/// @param filename
/// @param charset
@ -174,8 +155,6 @@ void AssExporter::Export(wxString filename, wxString charset, wxWindow *export_d
Subs->Save(filename,false,false,charset);
}
/// @brief Get window associated with name
/// @param name
/// @return
@ -186,8 +165,6 @@ wxSizer *AssExporter::GetSettingsSizer(wxString name) {
else return pos->second;
}
/// @brief Get description of filter
/// @param name
///
@ -201,5 +178,3 @@ wxString AssExporter::GetDescription(wxString name) {
}
throw wxString::Format(_T("Filter not found: %s"), name.c_str());
}

View file

@ -70,6 +70,7 @@ namespace std {
/// @brief AssFile constructor
AssFile::AssFile ()
: loaded(false)
, commitId(-1)
{
}
@ -109,16 +110,17 @@ void AssFile::Load (const wxString &_filename,wxString charset,bool addToRecent)
// Read file
if (reader) {
reader->SetTarget(this);
AssFile temp;
reader->SetTarget(&temp);
reader->ReadFile(_filename,charset);
swap(temp);
ok = true;
}
// Couldn't find a type
else throw _T("Unknown file type.");
}
// String error
catch (agi::UserCancelException const&) { }
catch (const wchar_t *except) {
wxMessageBox(except,_T("Error loading file"),wxICON_ERROR | wxOK);
}
@ -154,7 +156,7 @@ void AssFile::Load (const wxString &_filename,wxString charset,bool addToRecent)
savedCommitId = commitId;
// Add to recent
if (addToRecent) AddToRecent(_filename);
if (addToRecent && ok) AddToRecent(_filename);
}
void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) {

View file

@ -920,6 +920,16 @@ void AudioDisplay::SetFile(wxString file) {
// Update
UpdateImage();
}
catch (agi::UserCancelException const&) {
return;
}
catch (agi::FileNotFoundError const& e) {
config::mru->Remove("Audio", STD_STR(file));
wxMessageBox(lagi_wxString(e.GetMessage()), L"Error loading audio",wxICON_ERROR | wxOK);
}
catch (AudioOpenError const& e) {
wxMessageBox(lagi_wxString(e.GetMessage()), L"Error loading audio",wxICON_ERROR | wxOK);
}
catch (const wxChar *e) {
if (player) { delete player; player = 0; }
if (provider) { delete provider; provider = 0; }

View file

@ -34,16 +34,12 @@
/// @ingroup audio_ui
///
///////////
// Headers
#include "config.h"
#ifndef AGI_PRE
#include <algorithm>
#include <wx/dcclient.h>
#include <wx/log.h>
#include <wx/menu.h>
#include <wx/settings.h>
#include <wx/tokenzr.h>
@ -56,7 +52,6 @@
#include "audio_display.h"
#include "audio_karaoke.h"
/// @brief Empty constructor
///
AudioKaraokeSyllable::AudioKaraokeSyllable()
@ -66,7 +61,6 @@ AudioKaraokeSyllable::AudioKaraokeSyllable()
{
}
/// @brief Copy-from-base constructor
/// @param base
///
@ -77,9 +71,6 @@ AudioKaraokeSyllable::AudioKaraokeSyllable(const AssKaraokeSyllable &base)
{
}
/// @brief Constructor
/// @param parent
///
@ -95,16 +86,12 @@ AudioKaraoke::AudioKaraoke(wxWindow *parent)
workDiag = 0;
}
/// @brief Destructor
///
AudioKaraoke::~AudioKaraoke() {
delete workDiag;
}
/// @brief Load from dialogue
/// @param _diag
/// @return
@ -149,8 +136,6 @@ bool AudioKaraoke::LoadFromDialogue(AssDialogue *_diag) {
return !hasKar;
}
/// @brief Writes line back
/// @return
///
@ -196,8 +181,6 @@ void AudioKaraoke::Commit() {
LOG_D("karaoke/audio") << "returning";
}
/// @brief Autosplit line
/// @return
///
@ -253,8 +236,6 @@ void AudioKaraoke::AutoSplit() {
LOG_D("karaoke/audio") << "returning";
}
/// @brief Parses text to extract karaoke
/// @param curDiag
/// @return
@ -287,8 +268,6 @@ bool AudioKaraoke::ParseDialogue(AssDialogue *curDiag) {
return found_kara;
}
/// @brief Set syllable
/// @param n
/// @return
@ -304,7 +283,6 @@ void AudioKaraoke::SetSyllable(int n) {
LOG_D("karaoke/audio") << "returning";
}
///////////////
// Event table
BEGIN_EVENT_TABLE(AudioKaraoke,wxWindow)
@ -313,8 +291,6 @@ BEGIN_EVENT_TABLE(AudioKaraoke,wxWindow)
EVT_MOUSE_EVENTS(AudioKaraoke::OnMouse)
END_EVENT_TABLE()
/// @brief Paint event
/// @param event
///
@ -425,8 +401,6 @@ void AudioKaraoke::OnPaint(wxPaintEvent &event) {
event.Skip();
}
/// @brief Size event
/// @param event
///
@ -434,8 +408,6 @@ void AudioKaraoke::OnSize(wxSizeEvent &event) {
Refresh(false);
}
/// @brief Mouse event
/// @param event
/// @return
@ -571,8 +543,6 @@ void AudioKaraoke::OnMouse(wxMouseEvent &event) {
}
}
/// @brief Get Syllable at position X
/// @param x
/// @return
@ -590,8 +560,6 @@ int AudioKaraoke::GetSylAtX(int x) {
return -1;
}
/// @brief Set selection
/// @param start
/// @param end
@ -628,8 +596,6 @@ void AudioKaraoke::SetSelection(int start,int end) {
box->SetKaraokeButtons();
}
/// @brief Join syllables
/// @return
///
@ -675,8 +641,6 @@ void AudioKaraoke::Join() {
LOG_D("karaoke/audio") << "returning";
}
/// @brief Enter splitting-mode
///
void AudioKaraoke::BeginSplit() {
@ -688,8 +652,6 @@ void AudioKaraoke::BeginSplit() {
Refresh(false);
}
/// @brief Leave splitting-mode, committing changes
/// @param commit
/// @return
@ -727,8 +689,6 @@ void AudioKaraoke::EndSplit(bool commit) {
LOG_D("karaoke/audio") << "returning";
}
/// @brief Split a syllable using the pending_slits data
/// @param n
/// @return
@ -799,8 +759,6 @@ int AudioKaraoke::SplitSyl (unsigned int n) {
return numsplits;
}
/// @brief Apply delta length to syllable
/// @param n
/// @param delta
@ -855,8 +813,6 @@ bool AudioKaraoke::SyllableDelta(int n,int delta,int mode) {
return false;
}
/// @brief Karaoke tag menu constructor
/// @param _kara
///
@ -884,22 +840,17 @@ AudioKaraokeTagMenu::AudioKaraokeTagMenu(AudioKaraoke *_kara)
}
}
/// @brief Karaoke tag menu destructor
///
AudioKaraokeTagMenu::~AudioKaraokeTagMenu() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(AudioKaraokeTagMenu,wxMenu)
EVT_MENU_RANGE(10001, 10003, AudioKaraokeTagMenu::OnSelectItem)
END_EVENT_TABLE()
/// @brief Karaoke tag menu event handler
/// @param event
///
@ -934,6 +885,3 @@ void AudioKaraokeTagMenu::OnSelectItem(wxCommandEvent &event) {
kara->SetSelection(firstsel, lastsel);
}

View file

@ -34,10 +34,8 @@
/// @ingroup audio_output
///
#include "config.h"
#ifdef WITH_ALSA
#include <libaegisub/log.h>
@ -48,7 +46,6 @@
#include "frame_main.h"
#include "utils.h"
/// @brief Constructor
///
AlsaPlayer::AlsaPlayer()

View file

@ -34,16 +34,12 @@
/// @ingroup audio_output
///
#ifdef WITH_ALSA
#include <alsa/asoundlib.h>
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "utils.h"
/// DOCME
/// @class AlsaPlayer
@ -62,7 +58,6 @@ private:
/// DOCME
volatile float volume;
/// DOCME
volatile unsigned long start_frame; // first frame of playback
@ -75,7 +70,6 @@ private:
/// DOCME
unsigned long bpf; // bytes per frame
/// DOCME
AudioProvider *provider;
@ -88,7 +82,6 @@ private:
/// DOCME
snd_async_handler_t *pcm_callback;
/// DOCME
snd_pcm_format_t sample_format;
@ -132,7 +125,6 @@ public:
void SetEndPosition(int64_t pos);
void SetCurrentPosition(int64_t pos);
/// @brief DOCME
/// @param vol
/// @return

View file

@ -34,9 +34,6 @@
/// @ingroup audio_output
///
///////////
// Headers
#include "config.h"
#ifdef WITH_DIRECTSOUND
@ -48,7 +45,6 @@
#include "main.h"
#include "utils.h"
/// @brief Constructor
///
DirectSoundPlayer::DirectSoundPlayer() {
@ -64,16 +60,12 @@ DirectSoundPlayer::DirectSoundPlayer() {
thread = NULL;
}
/// @brief Destructor
///
DirectSoundPlayer::~DirectSoundPlayer() {
CloseStream();
}
/// @brief Open stream
///
void DirectSoundPlayer::OpenStream() {
@ -125,8 +117,6 @@ void DirectSoundPlayer::OpenStream() {
offset = 0;
}
/// @brief Close stream
///
void DirectSoundPlayer::CloseStream() {
@ -146,8 +136,6 @@ void DirectSoundPlayer::CloseStream() {
}
}
/// @brief Fill buffer
/// @param fill
/// @return
@ -237,8 +225,6 @@ RetryLock:
return playPos < endPos;
}
/// @brief Play
/// @param start
/// @param count
@ -281,8 +267,6 @@ void DirectSoundPlayer::Play(int64_t start,int64_t count) {
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
}
/// @brief Stop
/// @param timerToo
///
@ -313,8 +297,6 @@ void DirectSoundPlayer::Stop(bool timerToo) {
}
}
/// @brief Set end
/// @param pos
///
@ -322,8 +304,6 @@ void DirectSoundPlayer::SetEndPosition(int64_t pos) {
if (playing) endPos = pos;
}
/// @brief Set current position
/// @param pos
///
@ -332,8 +312,6 @@ void DirectSoundPlayer::SetCurrentPosition(int64_t pos) {
startTime = GetTickCount();
}
/// @brief Get current position
/// @return
///
@ -348,8 +326,6 @@ int64_t DirectSoundPlayer::GetCurrentPosition() {
return startPos + tdiff * provider->GetSampleRate() / 1000;
}
/// @brief Thread constructor
/// @param par
///
@ -358,16 +334,12 @@ DirectSoundPlayerThread::DirectSoundPlayerThread(DirectSoundPlayer *par) : wxThr
stopnotify = CreateEvent(NULL, true, false, NULL);
}
/// @brief Thread destructor
///
DirectSoundPlayerThread::~DirectSoundPlayerThread() {
CloseHandle(stopnotify);
}
/// @brief Thread entry point
/// @return
///
@ -418,8 +390,6 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() {
return 0;
}
/// @brief Stop playback thread
///
void DirectSoundPlayerThread::Stop() {
@ -429,4 +399,3 @@ void DirectSoundPlayerThread::Stop() {
#endif // WITH_DIRECTSOUND

View file

@ -34,9 +34,6 @@
/// @ingroup audio_output
///
///////////
// Headers
#ifdef WITH_DIRECTSOUND
#ifndef AGI_PRE
@ -47,15 +44,9 @@
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "utils.h"
//////////////
// Prototypes
class DirectSoundPlayer;
/// DOCME
/// @class DirectSoundPlayerThread
/// @brief DOCME
@ -93,8 +84,6 @@ detect which were actually changed and act accordingly.
All but GetPosition() set appropriate fields and then raise the parameters changed event.
*/
/// DOCME
/// @class DirectSoundPlayer
/// @brief DOCME
@ -117,7 +106,6 @@ private:
/// DOCME
DWORD bufSize;
/// DOCME
volatile int64_t playPos;
@ -130,7 +118,6 @@ private:
/// DOCME
DWORD startTime;
/// DOCME
IDirectSound8 *directSound;
@ -139,7 +126,6 @@ private:
bool FillBuffer(bool fill);
/// DOCME
DirectSoundPlayerThread *thread;
@ -158,7 +144,6 @@ public:
///
bool IsPlaying() { return playing; }
/// @brief DOCME
/// @return
///
@ -172,7 +157,6 @@ public:
void SetEndPosition(int64_t pos);
void SetCurrentPosition(int64_t pos);
/// @brief DOCME
/// @param vol
/// @return

View file

@ -44,17 +44,6 @@
#include "frame_main.h"
#include "utils.h"
#ifdef __WINDOWS__
#include <al.h>
#include <alc.h>
#elif defined(__APPLE__)
#include <OpenAL/AL.h>
#include <OpenAL/ALC.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#endif
// Auto-link to OpenAL lib for MSVC
#ifdef _MSC_VER
#pragma comment(lib, "openal32.lib")
@ -78,8 +67,6 @@ OpenALPlayer::~OpenALPlayer()
CloseStream();
}
/// @brief Open stream
///
void OpenALPlayer::OpenStream()
@ -135,8 +122,6 @@ void OpenALPlayer::OpenStream()
open = true;
}
/// @brief Close stream
/// @return
///
@ -155,8 +140,6 @@ void OpenALPlayer::CloseStream()
open = false;
}
/// @brief Play
/// @param start
/// @param count
@ -192,8 +175,6 @@ void OpenALPlayer::Play(int64_t start,int64_t count)
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
}
/// @brief Stop
/// @param timerToo
/// @return
@ -219,8 +200,6 @@ void OpenALPlayer::Stop(bool timerToo)
}
}
/// @brief DOCME
/// @param count
///
@ -261,8 +240,6 @@ void OpenALPlayer::FillBuffers(ALsizei count)
free(data);
}
/// @brief DOCME
///
void OpenALPlayer::Notify()
@ -300,8 +277,6 @@ void OpenALPlayer::Notify()
}
}
/// @brief DOCME
/// @return
///
@ -310,8 +285,6 @@ bool OpenALPlayer::IsPlaying()
return playing;
}
/// @brief Set end
/// @param pos
///
@ -320,8 +293,6 @@ void OpenALPlayer::SetEndPosition(int64_t pos)
end_frame = pos;
}
/// @brief Set current position
/// @param pos
///
@ -330,8 +301,6 @@ void OpenALPlayer::SetCurrentPosition(int64_t pos)
cur_frame = pos;
}
/// @brief DOCME
/// @return
///
@ -340,8 +309,6 @@ int64_t OpenALPlayer::GetStartPosition()
return start_frame;
}
/// @brief DOCME
/// @return
///
@ -350,8 +317,6 @@ int64_t OpenALPlayer::GetEndPosition()
return end_frame;
}
/// @brief Get current position
///
int64_t OpenALPlayer::GetCurrentPosition()
@ -362,5 +327,4 @@ int64_t OpenALPlayer::GetCurrentPosition()
return buffers_played * buffer_length + start_frame + extra * samplerate / 1000;
}
#endif // WITH_OPENAL

View file

@ -34,11 +34,9 @@
/// @ingroup audio_output
///
#ifdef WITH_OPENAL
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "utils.h"
#ifdef __WINDOWS__
#include <al.h>
@ -68,7 +66,6 @@ private:
/// DOCME
volatile float volume;
/// DOCME
static const ALsizei num_buffers = 8;
@ -78,7 +75,6 @@ private:
/// DOCME
ALsizei samplerate;
/// DOCME
volatile unsigned long start_frame; // first frame of playback
@ -91,7 +87,6 @@ private:
/// DOCME
unsigned long bpf; // bytes per frame
/// DOCME
AudioProvider *provider;
@ -107,7 +102,6 @@ private:
/// DOCME
ALuint source; // playback source
/// DOCME
ALsizei buf_first_free; // index into buffers, first free (unqueued) buffer
@ -145,7 +139,6 @@ public:
void SetEndPosition(int64_t pos);
void SetCurrentPosition(int64_t pos);
/// @brief DOCME
/// @param vol
/// @return

View file

@ -32,7 +32,6 @@
/// @ingroup audio_output
///
#include "config.h"
#ifdef WITH_OSS
@ -45,7 +44,6 @@
#include "main.h"
#include "utils.h"
/// @brief Constructor
///
OSSPlayer::OSSPlayer()
@ -58,8 +56,6 @@ OSSPlayer::OSSPlayer()
thread = 0;
}
/// @brief Destructor
///
OSSPlayer::~OSSPlayer()
@ -67,8 +63,6 @@ OSSPlayer::~OSSPlayer()
CloseStream();
}
/// @brief Open stream
///
void OSSPlayer::OpenStream()
@ -125,8 +119,6 @@ void OSSPlayer::OpenStream()
open = true;
}
/// @brief Close stream
/// @return
///
@ -141,8 +133,6 @@ void OSSPlayer::CloseStream()
open = false;
}
/// @brief Play
/// @param start
/// @param count
@ -163,8 +153,6 @@ void OSSPlayer::Play(int64_t start, int64_t count)
playing = true;
}
/// @brief Stop
/// @param timerToo
/// @return
@ -198,8 +186,6 @@ void OSSPlayer::Stop(bool timerToo)
}
}
/// @brief DOCME
/// @return
///
@ -208,8 +194,6 @@ bool OSSPlayer::IsPlaying()
return playing;
}
/// @brief Set end
/// @param pos
///
@ -225,8 +209,6 @@ void OSSPlayer::SetEndPosition(int64_t pos)
}
/// @brief Set current position
/// @param pos
///
@ -235,8 +217,6 @@ void OSSPlayer::SetCurrentPosition(int64_t pos)
cur_frame = start_frame = pos;
}
/// @brief DOCME
/// @return
///
@ -245,8 +225,6 @@ int64_t OSSPlayer::GetStartPosition()
return start_frame;
}
/// @brief DOCME
/// @return
///
@ -255,8 +233,6 @@ int64_t OSSPlayer::GetEndPosition()
return end_frame;
}
/// @brief Get current position
/// @return
///
@ -305,8 +281,6 @@ int64_t OSSPlayer::GetCurrentPosition()
return cur_frame;
}
/// @brief Thread constructor
/// @param par
///
@ -338,6 +312,4 @@ wxThread::ExitCode OSSPlayerThread::Entry() {
return 0;
}
#endif // WITH_OSS

View file

@ -52,7 +52,6 @@
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "utils.h"
class OSSPlayer;
@ -73,8 +72,6 @@ public:
wxThread::ExitCode Entry();
};
/// DOCME
/// @class OSSPlayer
/// @brief DOCME

View file

@ -34,13 +34,13 @@
/// @ingroup audio_output
///
#ifdef WITH_PORTAUDIO
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "utils.h"
extern "C" {
"C" {
#include <portaudio.h>
}

View file

@ -35,15 +35,10 @@
///
#ifdef WITH_PULSEAUDIO
#ifndef AGI_PRE
#include <stdio.h>
#endif
#include <pulse/pulseaudio.h>
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "utils.h"
class PulseAudioPlayer;

View file

@ -178,66 +178,69 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count,
///
AudioProvider *AudioProviderFactory::GetProvider(wxString filename, int cache) {
AudioProvider *provider = NULL;
bool found = false;
std::string msg;
if (!OPT_GET("Provider/Audio/PCM/Disable")->GetBool()) {
// Try a PCM provider first
provider = CreatePCMAudioProvider(filename);
if (provider) {
if (provider->GetBytesPerSample() == 2 && provider->GetSampleRate() >= 32000 && provider->GetChannels() == 1)
return provider;
else {
return CreateConvertAudioProvider(provider);
try {
provider = CreatePCMAudioProvider(filename);
}
catch (agi::FileNotFoundError const& err) {
msg = "PCM audio provider: " + err.GetMessage() + " not found.\n";
}
catch (AudioOpenError const& err) {
found = true;
msg += err.GetMessage();
}
}
if (!provider) {
std::vector<std::string> list = GetClasses(OPT_GET("Audio/Provider")->GetString());
if (list.empty()) throw AudioOpenError("No audio providers are available.");
for (unsigned int i=0;i<list.size();i++) {
try {
provider = Create(list[i], filename);
if (provider) break;
}
catch (agi::FileNotFoundError const& err) {
msg += list[i] + ": " + err.GetMessage() + " not found.\n";
}
catch (AudioOpenError const& err) {
found = true;
msg += list[i] + ": " + err.GetMessage();
}
}
}
// List of providers
std::vector<std::string> list = GetClasses(OPT_GET("Audio/Provider")->GetString());
if (list.empty()) throw _T("No audio providers are available.");
// Get provider
wxString error;
for (unsigned int i=0;i<list.size();i++) {
try {
provider = Create(list[i], filename);
if (provider) break;
if (!provider) {
if (found) {
throw AudioOpenError(msg);
}
else {
throw agi::FileNotFoundError(STD_STR(filename));
}
catch (wxString err) { error += list[i] + _T(" factory: ") + err + _T("\n"); }
catch (const wxChar *err) { error += list[i] + _T(" factory: ") + wxString(err) + _T("\n"); }
catch (...) { error += list[i] + _T(" factory: Unknown error\n"); }
}