This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
/
DLNAMediaAudio.java
496 lines (445 loc) · 10.9 KB
/
DLNAMediaAudio.java
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/*
* PS3 Media Server, for streaming any medias to your PS3.
* Copyright (C) 2008 A.Brochard
*
* This program 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; version 2
* of the License only.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.pms.dlna;
/**
* This class keeps track of the audio properties of media.
*
* TODO: Change all instance variables to private. For backwards compatibility
* with external plugin code the variables have all been marked as deprecated
* instead of changed to private, but this will surely change in the future.
* When everything has been changed to private, the deprecated note can be
* removed.
*/
public class DLNAMediaAudio extends DLNAMediaLang implements Cloneable {
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public int bitsperSample;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public String sampleFrequency;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public int nrAudioChannels;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public String codecA;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public String album;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public String artist;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public String songname;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public String genre;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public int year;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public int track;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public int delay;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public String flavor;
/**
* @deprecated Use standard getter and setter to access this variable.
*/
@Deprecated
public String muxingModeAudio;
/**
* Constructor
*/
public DLNAMediaAudio() {
setBitsperSample(16);
}
/**
* Returns the sample rate for this audio media.
*
* @return The sample rate.
*/
public int getSampleRate() {
int sr = 0;
if (getSampleFrequency() != null && getSampleFrequency().length() > 0) {
try {
sr = Integer.parseInt(getSampleFrequency());
} catch (NumberFormatException e) {
}
}
return sr;
}
/**
* Returns true if this media uses the AC3 audio codec, false otherwise.
*
* @return True if the AC3 audio codec is used.
*/
public boolean isAC3() {
return getCodecA() != null && (getCodecA().equalsIgnoreCase("ac3") || getCodecA().equalsIgnoreCase("a52") || getCodecA().equalsIgnoreCase("liba52"));
}
/**
* Returns true if this media uses the TrueHD audio codec, false otherwise.
*
* @return True if the TrueHD audio codec is used.
*/
public boolean isTrueHD() {
return getCodecA() != null && getCodecA().equalsIgnoreCase("truehd");
}
/**
* Returns true if this media uses the TrueHD audio codec, false otherwise.
*
* @return True if the TrueHD audio codec is used.
*/
public boolean isDTS() {
return getCodecA() != null && (getCodecA().startsWith("dts") || getCodecA().equalsIgnoreCase("dca") || getCodecA().equalsIgnoreCase("dca (dts)"));
}
/**
* Returns true if this media uses an AC3, DTS or TrueHD codec, false otherwise.
*
* @return True if the AC3, DTS or TrueHD codec is used.
*/
public boolean isNonPCMEncodedAudio() {
return isAC3() || isDTS() || isTrueHD();
}
/**
* Returns true if this media uses the MP3 audio codec, false otherwise.
*
* @return True if the MP3 audio codec is used.
*/
public boolean isMP3() {
return getCodecA() != null && getCodecA().equalsIgnoreCase("mp3");
}
/**
* Returns true if this media uses audio that is PCM encoded, false otherwise.
*
* @return True if the audio is PCM encoded.
*/
public boolean isPCM() {
return getCodecA() != null && (getCodecA().startsWith("pcm") || getCodecA().equals("LPCM"));
}
/**
* Returns true if this media uses a lossless audio compression codec, false otherwise.
*
* @return True if the audio is lossless compressed.
*/
public boolean isLossless() {
return getCodecA() != null && (isPCM() || getCodecA().startsWith("fla") || getCodecA().equals("mlp") || getCodecA().equals("wv"));
}
/**
* Returns a standardized name for the audio codec that is used.
*
* @return The standardized name.
*/
public String getAudioCodec() {
if (isAC3()) {
return "AC3";
} else if (isDTS()) {
return "DTS";
} else if (isTrueHD()) {
return "TrueHD";
} else if (isPCM()) {
return "LPCM";
} else if (getCodecA() != null && getCodecA().equals("vorbis")) {
return "OGG";
} else if (getCodecA() != null && getCodecA().equals("aac")) {
return "AAC";
} else if (getCodecA() != null && getCodecA().equals("mp3")) {
return "MP3";
} else if (getCodecA() != null && getCodecA().startsWith("wm")) {
return "WMA";
} else if (getCodecA() != null && getCodecA().equals("mp2")) {
return "Mpeg Audio";
}
return getCodecA() != null ? getCodecA() : "-";
}
/**
* Returns the identifying name for the audio properties.
*
* @return The name.
*/
public String toString() {
return "Audio: " + getAudioCodec() + " / lang: " + getLang() + " / flavor: " + getFlavor() + " / ID: " + getId();
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
/**
* Returns the number of bits per sample for the audio.
*
* @return The number of bits per sample.
* @since 1.50
*/
public int getBitsperSample() {
return bitsperSample;
}
/**
* Sets the number of bits per sample for the audio.
*
* @param bitsperSample The number of bits per sample to set.
* @since 1.50
*/
public void setBitsperSample(int bitsperSample) {
this.bitsperSample = bitsperSample;
}
/**
* Returns the sample frequency for the audio.
*
* @return The sample frequency.
* @since 1.50
*/
public String getSampleFrequency() {
return sampleFrequency;
}
/**
* Sets the sample frequency for the audio.
*
* @param sampleFrequency The sample frequency to set.
* @since 1.50
*/
public void setSampleFrequency(String sampleFrequency) {
this.sampleFrequency = sampleFrequency;
}
/**
* Returns the number of channels for the audio.
*
* @return The number of channels
* @since 1.50
*/
public int getNrAudioChannels() {
return nrAudioChannels;
}
/**
* Sets the number of channels for the audio.
*
* @param nrAudioChannels The number of channels to set.
* @since 1.50
*/
public void setNrAudioChannels(int nrAudioChannels) {
this.nrAudioChannels = nrAudioChannels;
}
/**
* Returns the name of the audio codec that is being used.
*
* @return The name of the audio codec.
* @since 1.50
*/
public String getCodecA() {
return codecA;
}
/**
* Sets the name of the audio codec that is being used.
*
* @param codecA The name of the audio codec to set.
* @since 1.50
*/
public void setCodecA(String codecA) {
this.codecA = codecA;
}
/**
* Returns the name of the album to which an audio track belongs.
*
* @return The album name.
* @since 1.50
*/
public String getAlbum() {
return album;
}
/**
* Sets the name of the album to which an audio track belongs.
*
* @param album The name of the album to set.
* @since 1.50
*/
public void setAlbum(String album) {
this.album = album;
}
/**
* Returns the name of the artist performing the audio track.
*
* @return The artist name.
* @since 1.50
*/
public String getArtist() {
return artist;
}
/**
* Sets the name of the artist performing the audio track.
*
* @param artist The artist name to set.
* @since 1.50
*/
public void setArtist(String artist) {
this.artist = artist;
}
/**
* Returns the name of the song for the audio track.
*
* @return The song name.
* @since 1.50
*/
public String getSongname() {
return songname;
}
/**
* Sets the name of the song for the audio track.
*
* @param songname The song name to set.
* @since 1.50
*/
public void setSongname(String songname) {
this.songname = songname;
}
/**
* Returns the name of the genre for the audio track.
*
* @return The genre name.
* @since 1.50
*/
public String getGenre() {
return genre;
}
/**
* Sets the name of the genre for the audio track.
*
* @param genre The name of the genre to set.
* @since 1.50
*/
public void setGenre(String genre) {
this.genre = genre;
}
/**
* Returns the year of inception for the audio track.
*
* @return The year.
* @since 1.50
*/
public int getYear() {
return year;
}
/**
* Sets the year of inception for the audio track.
*
* @param year The year to set.
* @since 1.50
*/
public void setYear(int year) {
this.year = year;
}
/**
* Returns the track number within an album for the audio.
*
* @return The track number.
* @since 1.50
*/
public int getTrack() {
return track;
}
/**
* Sets the track number within an album for the audio.
*
* @param track The track number to set.
* @since 1.50
*/
public void setTrack(int track) {
this.track = track;
}
/**
* Returns the delay for the audio.
*
* @return The delay.
* @since 1.50
*/
public int getDelay() {
return delay;
}
/**
* Sets the delay for the audio.
*
* @param delay The delay to set.
* @since 1.50
*/
public void setDelay(int delay) {
this.delay = delay;
}
/**
* Returns the flavor for the audio.
*
* @return The flavor.
* @since 1.50
*/
public String getFlavor() {
return flavor;
}
/**
* Sets the flavor for the audio.
*
* @param flavor The flavor to set.
* @since 1.50
*/
public void setFlavor(String flavor) {
this.flavor = flavor;
}
/**
* Returns the audio codec to use for muxing.
*
* @return The audio codec to use.
* @since 1.50
*/
public String getMuxingModeAudio() {
return muxingModeAudio;
}
/**
* Sets the audio codec to use for muxing.
*
* @param muxingModeAudio The audio codec to use.
* @since 1.50
*/
public void setMuxingModeAudio(String muxingModeAudio) {
this.muxingModeAudio = muxingModeAudio;
}
}