source: trunk/poppler/mypoppler/poppler/Sound.cc @ 461

Last change on this file since 461 was 277, checked in by rbri, 12 years ago

PDF plugin: Poppler library updated to version 0.12.3

File size: 3.5 KB
Line 
1/* Sound.cc - an object that holds the sound structure
2 * Copyright (C) 2006-2007, Pino Toscano <pino@kde.org>
3 * Copyright (C) 2009, 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 "GooString.h"
21#include "Object.h"
22#include "Sound.h"
23#include "Stream.h"
24#include "FileSpec.h"
25
26Sound *Sound::parseSound(Object *obj)
27{
28  // let's try to see if this Object is a Sound, according to the PDF specs
29  // (section 9.2)
30  Stream *str = NULL;
31  // the Object must be a Stream
32  if (obj->isStream()) {
33    str = obj->getStream();
34  } else {
35    return NULL;
36  }
37  // the Stream must have a Dict
38  Dict *dict = str->getDict();
39  if (dict == NULL)
40    return NULL;
41  Object tmp;
42  // the Dict must have the 'R' key of type num
43  dict->lookup("R", &tmp);
44  if (tmp.isNum()) {
45    return new Sound(obj);
46  } else {
47    return NULL;
48  }
49}
50
51Sound::Sound(Object *obj, bool readAttrs)
52{
53  streamObj = new Object();
54  streamObj->initNull();
55  obj->copy(streamObj);
56
57  fileName = NULL;
58  samplingRate = 0.0;
59  channels = 1;
60  bitsPerSample = 8;
61  encoding = soundRaw;
62
63  if (readAttrs)
64  {
65    Object tmp;
66    Dict *dict = streamObj->getStream()->getDict();
67    dict->lookup("F", &tmp);
68    if (!tmp.isNull()) {
69      Object obj1;
70      // valid 'F' key -> external file
71      kind = soundExternal;
72      if (getFileSpecNameForPlatform (&tmp, &obj1)) {
73        fileName = obj1.getString()->copy();
74        obj1.free();
75      }
76    } else {
77      // no file specification, then the sound data have to be
78      // extracted from the stream
79      kind = soundEmbedded;
80    }
81    tmp.free();
82    // sampling rate
83    dict->lookup("R", &tmp);
84    if (tmp.isNum()) {
85      samplingRate = tmp.getNum();
86    }
87    tmp.free();
88    // sound channels
89    dict->lookup("C", &tmp);
90    if (tmp.isInt()) {
91      channels = tmp.getInt();
92    }
93    tmp.free();
94    // bits per sample
95    dict->lookup("B", &tmp);
96    if (tmp.isInt()) {
97      bitsPerSample = tmp.getInt();
98    }
99    tmp.free();
100    // encoding format
101    dict->lookup("E", &tmp);
102    if (tmp.isName())
103    {
104      const char *enc = tmp.getName();
105      if (strcmp("Raw", enc) == 0) {
106        encoding = soundRaw;
107      } else if (strcmp("Signed", enc) == 0) {
108        encoding = soundSigned;
109      } else if (strcmp("muLaw", enc) == 0) {
110        encoding = soundMuLaw;
111      } else if (strcmp("ALaw", enc) == 0) {
112        encoding = soundALaw;
113      }
114    }
115    tmp.free();
116  }
117}
118
119Sound::~Sound()
120{
121  delete fileName;
122  streamObj->free();
123  delete streamObj;
124}
125
126Stream *Sound::getStream()
127{
128  return streamObj->getStream();
129}
130
131Sound *Sound::copy()
132{
133  Sound *newsound = new Sound(streamObj, false);
134
135  newsound->kind = kind;
136  if (fileName) {
137    newsound->fileName = fileName->copy();
138  }
139  newsound->samplingRate = samplingRate;
140  newsound->channels = channels;
141  newsound->bitsPerSample = bitsPerSample;
142  newsound->encoding = encoding;
143
144  return newsound;
145}
Note: See TracBrowser for help on using the repository browser.