forked from carlonluca/pot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomx_playeraudio.cpp
141 lines (122 loc) · 4.39 KB
/
omx_playeraudio.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
/*
* Project: PiOmxTextures
* Author: Luca Carlon
* Date: 07.20.2013
*
* Copyright (c) 2012, 2013 Luca Carlon. All rights reserved.
*
* This file is part of PiOmxTextures.
*
* PiOmxTextures is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PiOmxTextures is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PiOmxTextures. If not, see <http://www.gnu.org/licenses/>.
*/
/*------------------------------------------------------------------------------
| includes
+-----------------------------------------------------------------------------*/
#include <Qt>
#include <cmath>
#include "omx_playeraudio.h"
#include "lc_logging.h"
using namespace std;
/*------------------------------------------------------------------------------
| OMX_PlayerAudio::OMX_PlayerAudio
+-----------------------------------------------------------------------------*/
OMX_PlayerAudio::OMX_PlayerAudio() : OMXPlayerAudio()
{
// Do nothing.
}
/*------------------------------------------------------------------------------
| OMX_PlayerAudio::~OMX_PlayerAudio
+-----------------------------------------------------------------------------*/
OMX_PlayerAudio::~OMX_PlayerAudio()
{
// Do nothing.
}
/*------------------------------------------------------------------------------
| OMX_PlayerAudio::SetMuted
+-----------------------------------------------------------------------------*/
void OMX_PlayerAudio::SetMuted(bool mute)
{
m_mute = mute;
if (m_decoder)
m_decoder->SetMute(m_mute);
}
/*------------------------------------------------------------------------------
| OMX_PlayerAudio::GetMuted
+-----------------------------------------------------------------------------*/
bool OMX_PlayerAudio::GetMuted()
{
return m_mute;
}
/*------------------------------------------------------------------------------
| OMX_PlayerAudio::SetCurrentVolume
+-----------------------------------------------------------------------------*/
/**
* @brief OMX_PlayerAudio::SetCurrentVolume
* @param volume Volume in mB or percentage [0, 100].
* @param linear
*/
void OMX_PlayerAudio::SetCurrentVolume(long volume, bool linear)
{
if (!linear) {
OMXPlayerAudio::SetVolume(volume);
return;
}
// I supposed it was possible to get the available range from OpenMAX
// but it seems to always return 0.
#ifdef ENABLE_RANGE_FROM_OMX
// Get current configuration to determine max and min mB.
OMX_AUDIO_CONFIG_VOLUMETYPE omxVolume;
OMX_INIT_STRUCTURE(omxVolume);
omxVolume.nPortIndex = m_decoder->m_omx_render.GetInputPort();
omxVolume.bLinear = OMX_FALSE;
OMX_ERRORTYPE omx_err = m_decoder->m_omx_render.GetConfig(OMX_IndexConfigAudioVolume, &omxVolume);
if (omx_err != OMX_ErrorNone) {
LOG_WARNING(LOG_TAG, "%s - error getting OMX_IndexConfigAudioVolume, error 0x%08x\n",
Q_FUNC_INFO, omx_err);
return;
}
// Determine the mB value to be used.
OMX_S32 mbMax = omxVolume.sVolume.nMax;
OMX_S32 mbMin = omxVolume.sVolume.nMin;
#else
OMX_S32 mbMax = 2;
OMX_S32 mbMin = -6;
#endif
double expMin = exp(mbMin);
double expMax = exp(mbMax);
double mbVolume = log((double)volume/100*(expMax - expMin) + expMin);
LOG_VERBOSE(LOG_TAG, "Setting volume to %fmB.", mbVolume);
// omxplayer expects millibels here.
OMXPlayerAudio::SetVolume(mbVolume*1000);
}
/*------------------------------------------------------------------------------
| OMX_PlayerAudio::GetCurrentVolume
+-----------------------------------------------------------------------------*/
long OMX_PlayerAudio::GetCurrentVolume(bool linear)
{
return 0;
#if 0
long mbVol = OMXPlayerAudio::GetCurrentVolume();
if (!linear)
return mbVol;
OMX_S32 mbMax = 2;
OMX_S32 mbMin = -6;
double expMin = exp(mbMin);
double expMax = exp(mbMax);
double num = 100*exp(mbVol/1000) - expMin;
double den = expMax - expMin;
LOG_VERBOSE(LOG_TAG, "Volume: %ld.", (long)(num/den));
return (long)(num/den);
#endif
}