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
|
/*
* Copyright (C) 2010-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "cores/AudioEngine/Interfaces/AESound.h"
#include "ActiveAE.h"
#include "ActiveAESound.h"
#include "utils/log.h"
extern "C" {
#include <libavutil/avutil.h>
}
using namespace ActiveAE;
using namespace XFILE;
CActiveAESound::CActiveAESound(const std::string &filename, CActiveAE *ae) :
IAESound (filename),
m_filename (filename),
m_volume (1.0f ),
m_channel (AE_CH_NULL)
{
m_orig_sound = NULL;
m_dst_sound = NULL;
m_pFile = NULL;
m_isSeekPossible = false;
m_fileSize = 0;
m_isConverted = false;
m_activeAE = ae;
}
CActiveAESound::~CActiveAESound()
{
delete m_orig_sound;
delete m_dst_sound;
Finish();
}
void CActiveAESound::Play()
{
m_activeAE->PlaySound(this);
}
void CActiveAESound::Stop()
{
m_activeAE->StopSound(this);
}
bool CActiveAESound::IsPlaying()
{
//! @todo implement
return false;
}
uint8_t** CActiveAESound::InitSound(bool orig, SampleConfig config, int nb_samples)
{
CSoundPacket **info;
if (orig)
info = &m_orig_sound;
else
info = &m_dst_sound;
delete *info;
*info = new CSoundPacket(config, nb_samples);
(*info)->nb_samples = 0;
m_isConverted = false;
return (*info)->data;
}
bool CActiveAESound::StoreSound(bool orig, uint8_t **buffer, int samples, int linesize)
{
CSoundPacket **info;
if (orig)
info = &m_orig_sound;
else
info = &m_dst_sound;
if ((*info)->nb_samples + samples > (*info)->max_nb_samples)
{
CLog::Log(LOGERROR, "CActiveAESound::StoreSound - exceeded max samples");
return false;
}
int bytes_to_copy = samples * (*info)->bytes_per_sample * (*info)->config.channels;
bytes_to_copy /= (*info)->planes;
int start = (*info)->nb_samples * (*info)->bytes_per_sample * (*info)->config.channels;
start /= (*info)->planes;
for (int i=0; i<(*info)->planes; i++)
{
memcpy((*info)->data[i]+start, buffer[i], bytes_to_copy);
}
(*info)->nb_samples += samples;
return true;
}
CSoundPacket *CActiveAESound::GetSound(bool orig)
{
if (orig)
return m_orig_sound;
else
return m_dst_sound;
}
bool CActiveAESound::Prepare()
{
unsigned int flags = READ_TRUNCATED | READ_CHUNKED;
m_pFile = new CFile();
if (!m_pFile->Open(m_filename, flags))
{
delete m_pFile;
m_pFile = NULL;
return false;
}
m_isSeekPossible = m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL) != 0;
m_fileSize = m_pFile->GetLength();
return true;
}
void CActiveAESound::Finish()
{
delete m_pFile;
m_pFile = NULL;
}
int CActiveAESound::GetChunkSize()
{
return m_pFile->GetChunkSize();
}
int CActiveAESound::Read(void *h, uint8_t* buf, int size)
{
CFile *pFile = static_cast<CActiveAESound*>(h)->m_pFile;
int len = pFile->Read(buf, size);
if (len == 0)
return AVERROR_EOF;
else
return len;
}
int64_t CActiveAESound::Seek(void *h, int64_t pos, int whence)
{
CFile* pFile = static_cast<CActiveAESound*>(h)->m_pFile;
if(whence == AVSEEK_SIZE)
return pFile->GetLength();
else
return pFile->Seek(pos, whence & ~AVSEEK_FORCE);
}
|