Debian Codegraph @

qt6/src/poppler-sound.cc

raw
1 /* poppler-sound.cc: qt interface to poppler
2 * Copyright (C) 2006-2007, Pino Toscano <[email protected]>
3 * Copyright (C) 2008, 2018, 2020, Albert Astals Cid <[email protected]>
4 * Copyright (C) 2025, g10 Code GmbH, Author: Sune Stolborg Vuorela <[email protected]>
5 * Copyright (C) 2025, Arnav V <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 #include "poppler-qt6.h"
23
24 #include "Object.h"
25 #include "Stream.h"
26 #include "Sound.h"
27
28 namespace Poppler {
29
30 class SoundData
31 {
32 public:
33 SoundData() : m_soundObj(nullptr) { }
34
35 ~SoundData() { delete m_soundObj; }
36
37 SoundData(const SoundData &) = delete;
38 SoundData &operator=(const SoundData &) = delete;
39
40 SoundObject::SoundType m_type;
41 Sound *m_soundObj;
42 };
43
44 SoundObject::SoundObject(Sound *popplersound)
45 {
46 m_soundData = new SoundData();
47 switch (popplersound->getSoundKind()) {
48 case soundEmbedded:
49 m_soundData->m_type = SoundObject::Embedded;
50 break;
51 case soundExternal:
52 default:
53 m_soundData->m_type = SoundObject::External;
54 break;
55 }
56
57 m_soundData->m_soundObj = popplersound->copy();
58 }
59
60 SoundObject::~SoundObject()
61 {
62 delete m_soundData;
63 }
64
65 SoundObject::SoundType SoundObject::soundType() const
66 {
67 return m_soundData->m_type;
68 }
69
70 QString SoundObject::url() const
71 {
72 if (m_soundData->m_type != SoundObject::External) {
73 return QString();
74 }
75
76 return QString::fromStdString(m_soundData->m_soundObj->getFileName());
77 }
78
79 QByteArray SoundObject::data() const
80 {
81 if (m_soundData->m_type != SoundObject::Embedded) {
82 return QByteArray();
83 }
84
85 Stream *stream = m_soundData->m_soundObj->getStream();
86 if (!stream->rewind()) {
87 return QByteArray {};
88 }
89 int dataLen = 0;
90 QByteArray fileArray;
91 int i;
92 while ((i = stream->getChar()) != EOF) {
93 fileArray.append((char)i);
94 ++dataLen;
95 }
96 fileArray.resize(dataLen);
97
98 return fileArray;
99 }
100
101 double SoundObject::samplingRate() const
102 {
103 return m_soundData->m_soundObj->getSamplingRate();
104 }
105
106 int SoundObject::channels() const
107 {
108 return m_soundData->m_soundObj->getChannels();
109 }
110
111 int SoundObject::bitsPerSample() const
112 {
113 return m_soundData->m_soundObj->getBitsPerSample();
114 }
115
116 SoundObject::SoundEncoding SoundObject::soundEncoding() const
117 {
118 switch (m_soundData->m_soundObj->getEncoding()) {
119 case soundRaw:
120 return SoundObject::Raw;
121 case soundSigned:
122 return SoundObject::Signed;
123 case soundMuLaw:
124 return SoundObject::muLaw;
125 case soundALaw:
126 return SoundObject::ALaw;
127 }
128 return SoundObject::Raw;
129 }
130
131 }