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