forked from jfchapman/VUPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Handlers.cpp
171 lines (156 loc) · 4.05 KB
/
Handlers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "Handlers.h"
#include "HandlerBass.h"
#include "HandlerFFmpeg.h"
#include "HandlerFlac.h"
#include "HandlerMP3.h"
#include "HandlerOpus.h"
#include "HandlerPCM.h"
#include "HandlerWavpack.h"
#include "HandlerMAC.h"
#include "HandlerMPC.h"
#include "ShellMetadata.h"
#include "Utility.h"
Handlers::Handlers() :
m_HandlerBASS( new HandlerBass() ),
m_HandlerFFmpeg( new HandlerFFmpeg() ),
m_Handlers( {
Handler::Ptr( new HandlerFlac() ),
Handler::Ptr( new HandlerOpus() ),
Handler::Ptr( new HandlerWavpack() ),
Handler::Ptr( new HandlerMAC() ),
Handler::Ptr( new HandlerMPC() ),
Handler::Ptr( new HandlerMP3() ),
Handler::Ptr( new HandlerPCM() ),
Handler::Ptr( m_HandlerBASS ),
Handler::Ptr( m_HandlerFFmpeg )
} ),
m_Decoders(),
m_Encoders()
{
for ( const auto& handler : m_Handlers ) {
if ( handler ) {
if ( handler->IsDecoder() ) {
m_Decoders.push_back( handler );
}
if ( handler->IsEncoder() ) {
m_Encoders.push_back( handler );
}
}
}
}
Handlers::~Handlers()
{
}
Handler::Ptr Handlers::FindDecoderHandler( const std::wstring& filename ) const
{
Handler::Ptr handler;
const std::wstring extension = GetFileExtension( filename );
for ( auto decoder = m_Decoders.begin(); !handler && ( decoder != m_Decoders.end() ); decoder++ ) {
std::set<std::wstring> extensions = decoder->get()->GetSupportedFileExtensions();
const auto foundHandler = std::find( extensions.begin(), extensions.end(), extension );
if ( extensions.end() != foundHandler ) {
handler = *decoder;
break;
}
}
return handler;
}
Decoder::Ptr Handlers::OpenDecoder( const std::wstring& filename ) const
{
Decoder::Ptr decoder;
if ( IsURL( filename ) ) {
decoder = m_HandlerBASS ? m_HandlerBASS->OpenDecoder( filename ) : nullptr;
} else if ( !filename.empty() ) {
Handler::Ptr handler = FindDecoderHandler( filename );
if ( handler ) {
decoder = handler->OpenDecoder( filename );
}
if ( !decoder && m_HandlerFFmpeg ) {
// Try the FFmpeg handler as a catch all.
decoder = m_HandlerFFmpeg->OpenDecoder( filename );
}
}
return decoder;
}
bool Handlers::GetTags( const std::wstring& filename, Tags& tags ) const
{
bool success = false;
if ( !IsURL( filename ) ) {
tags.clear();
Handler::Ptr handler = FindDecoderHandler( filename );
if ( handler ) {
success = handler->GetTags( filename, tags );
}
if ( !success ) {
success = ShellMetadata::Get( filename, tags );
}
}
return success;
}
bool Handlers::SetTags( const std::wstring& filename, const Tags& tags ) const
{
bool success = false;
if ( !IsURL( filename ) ) {
Handler::Ptr handler = FindDecoderHandler( filename );
if ( handler ) {
success = handler->SetTags( filename, tags );
}
if ( !success ) {
success = ShellMetadata::Set( filename, tags );
}
}
return success;
}
std::set<std::wstring> Handlers::GetAllSupportedFileExtensions() const
{
std::set<std::wstring> fileExtensions;
for ( const auto& handler : m_Decoders ) {
std::set<std::wstring> handlerExtensions = handler->GetSupportedFileExtensions();
fileExtensions.insert( handlerExtensions.begin(), handlerExtensions.end() );
}
return fileExtensions;
}
std::wstring Handlers::GetBassVersion() const
{
std::wstring version;
for ( const auto& handler : m_Decoders ) {
if ( nullptr != dynamic_cast<HandlerBass*>( handler.get() ) ) {
version = handler->GetDescription();
break;
}
}
return version;
}
void Handlers::AddHandler( Handler::Ptr handler )
{
if ( handler ) {
m_Handlers.push_back( handler );
if ( handler->IsDecoder() ) {
m_Decoders.push_back( handler );
}
if ( handler->IsEncoder() ) {
m_Encoders.push_back( handler );
}
}
}
Handler::List Handlers::GetEncoders() const
{
return m_Encoders;
}
Encoder::Ptr Handlers::OpenEncoder( const std::wstring& /*description*/ ) const
{
Encoder::Ptr encoder;
return encoder;
}
void Handlers::SettingsChanged( Settings& settings ) const
{
for ( const auto& handler : m_Handlers ) {
if ( handler ) {
handler->SettingsChanged( settings );
}
}
}
void Handlers::Init( Settings& settings )
{
SettingsChanged( settings );
}