1/* poppler-media.cc: qt interface to poppler
2 * Copyright (C) 2012 Guillermo A. Amaral B. <gamaral@kde.org>
3 * Copyright (C) 2013, 2018, 2021 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-media.h"
21
22#include "Rendition.h"
23
24#include "poppler-private.h"
25
26#include <QtCore/QBuffer>
27
28#define BUFFER_MAX 4096
29
30namespace Poppler {
31
32class MediaRenditionPrivate
33{
34public:
35 explicit MediaRenditionPrivate(::MediaRendition *renditionA) : rendition(renditionA) { }
36
37 ~MediaRenditionPrivate() { delete rendition; }
38
39 MediaRenditionPrivate(const MediaRenditionPrivate &) = delete;
40 MediaRenditionPrivate &operator=(const MediaRenditionPrivate &) = delete;
41
42 ::MediaRendition *rendition;
43};
44
45MediaRendition::MediaRendition(::MediaRendition *rendition) : d_ptr(new MediaRenditionPrivate(rendition)) { }
46
47MediaRendition::~MediaRendition()
48{
49 delete d_ptr;
50}
51
52bool MediaRendition::isValid() const
53{
54 Q_D(const MediaRendition);
55 return d->rendition && d->rendition->isOk();
56}
57
58QString MediaRendition::contentType() const
59{
60 Q_ASSERT(isValid() && "Invalid media rendition.");
61 Q_D(const MediaRendition);
62 return UnicodeParsedString(s1: d->rendition->getContentType());
63}
64
65QString MediaRendition::fileName() const
66{
67 Q_ASSERT(isValid() && "Invalid media rendition.");
68 Q_D(const MediaRendition);
69 return UnicodeParsedString(s1: d->rendition->getFileName());
70}
71
72bool MediaRendition::isEmbedded() const
73{
74 Q_ASSERT(isValid() && "Invalid media rendition.");
75 Q_D(const MediaRendition);
76 return d->rendition->getIsEmbedded();
77}
78
79QByteArray MediaRendition::data() const
80{
81 Q_ASSERT(isValid() && "Invalid media rendition.");
82 Q_D(const MediaRendition);
83
84 Stream *s = d->rendition->getEmbbededStream();
85 if (!s) {
86 return QByteArray();
87 }
88
89 QBuffer buffer;
90 unsigned char data[BUFFER_MAX];
91 int bread;
92
93 buffer.open(openMode: QIODevice::WriteOnly);
94 s->reset();
95 while ((bread = s->doGetChars(BUFFER_MAX, buffer: data)) != 0) {
96 buffer.write(data: reinterpret_cast<const char *>(data), len: bread);
97 }
98 buffer.close();
99
100 return buffer.data();
101}
102
103bool MediaRendition::autoPlay() const
104{
105 Q_D(const MediaRendition);
106 if (d->rendition->getBEParameters()) {
107 return d->rendition->getBEParameters()->autoPlay;
108 } else if (d->rendition->getMHParameters()) {
109 return d->rendition->getMHParameters()->autoPlay;
110 } else {
111 qDebug(msg: "No BE or MH parameters to reference!");
112 }
113 return false;
114}
115
116bool MediaRendition::showControls() const
117{
118 Q_D(const MediaRendition);
119 if (d->rendition->getBEParameters()) {
120 return d->rendition->getBEParameters()->showControls;
121 } else if (d->rendition->getMHParameters()) {
122 return d->rendition->getMHParameters()->showControls;
123 } else {
124 qDebug(msg: "No BE or MH parameters to reference!");
125 }
126 return false;
127}
128
129float MediaRendition::repeatCount() const
130{
131 Q_D(const MediaRendition);
132 if (d->rendition->getBEParameters()) {
133 return d->rendition->getBEParameters()->repeatCount;
134 } else if (d->rendition->getMHParameters()) {
135 return d->rendition->getMHParameters()->repeatCount;
136 } else {
137 qDebug(msg: "No BE or MH parameters to reference!");
138 }
139 return 1.f;
140}
141
142QSize MediaRendition::size() const
143{
144 Q_D(const MediaRendition);
145 const MediaParameters *mp = nullptr;
146
147 if (d->rendition->getBEParameters()) {
148 mp = d->rendition->getBEParameters();
149 } else if (d->rendition->getMHParameters()) {
150 mp = d->rendition->getMHParameters();
151 } else {
152 qDebug(msg: "No BE or MH parameters to reference!");
153 }
154
155 if (mp) {
156 return QSize(mp->windowParams.width, mp->windowParams.height);
157 }
158 return QSize();
159}
160
161}
162

source code of poppler/qt6/src/poppler-media.cc