summaryrefslogtreecommitdiffstats
path: root/audio/format.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-23 22:44:54 +0200
committerwm4 <wm4@nowhere>2014-09-23 23:11:54 +0200
commit81bf9a196303f9d7a37db9365fc75022cb1eff19 (patch)
treeaea2758408e4fd1599cb34a7030f87f50f5d125c /audio/format.h
parent308d72a02ee673fc56b637b6134dd63ea258580c (diff)
downloadmpv-81bf9a196303f9d7a37db9365fc75022cb1eff19.tar.bz2
mpv-81bf9a196303f9d7a37db9365fc75022cb1eff19.tar.xz
audio: cleanup spdif format definitions
Before this commit, there was AF_FORMAT_AC3 (the original spdif format, used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS and DTS-HD), which was handled as some sort of superset for AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used IEC61937-framing, but still was handled as something "separate". Technically, all of them are pretty similar, but may use different bitrates. Since digital passthrough pretends to be PCM (just with special headers that wrap digital packets), this is easily detectable by the higher samplerate or higher number of channels, so I don't know why you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs. AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is just a mess. Simplify this by handling all these formats the same way. AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3). All AOs just accept all spdif formats now - whether that works or not is not really clear (seems inconsistent due to earlier attempts to make DTS-HD work). But on the other hand, enabling spdif requires manual user interaction, so it doesn't matter much if initialization fails in slightly less graceful ways if it can't work at all. At a later point, we will support passthrough with ao_pulse. It seems the PulseAudio API wants to know the codec type (or maybe not - feeding it DTS while telling it it's AC3 works), add separate formats for each codecs. While this reminds of the earlier chaos, it's stricter, and most code just uses AF_FORMAT_IS_IEC61937(). Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to include special formats, so that it always describes the fundamental sample format type. This also ensures valid AF formats are never 0 (this was probably broken in one of the earlier commits from today).
Diffstat (limited to 'audio/format.h')
-rw-r--r--audio/format.h69
1 files changed, 33 insertions, 36 deletions
diff --git a/audio/format.h b/audio/format.h
index 3662d817f1..06c5d566e5 100644
--- a/audio/format.h
+++ b/audio/format.h
@@ -28,39 +28,38 @@
#include "misc/bstr.h"
// Signed/unsigned
-#define AF_FORMAT_SI (0<<1) // Signed
-#define AF_FORMAT_US (1<<1) // Unsigned
-#define AF_FORMAT_SIGN_MASK (1<<1)
+#define AF_FORMAT_SI (0<<0) // Signed
+#define AF_FORMAT_US (1<<0) // Unsigned
+#define AF_FORMAT_SIGN_MASK (1<<0)
// Bits used
// Some code assumes they're sorted by size.
-#define AF_FORMAT_8BIT (0<<3)
-#define AF_FORMAT_16BIT (1<<3)
-#define AF_FORMAT_24BIT (2<<3)
-#define AF_FORMAT_32BIT (3<<3)
-#define AF_FORMAT_64BIT (4<<3)
-#define AF_FORMAT_BITS_MASK (7<<3)
-
-// Special flags refering to non pcm data (note: 1<<6, 2<<6, 5<<6 unused)
-#define AF_FORMAT_S_MPEG2 (3<<6) // MPEG(2) audio
-#define AF_FORMAT_S_AC3 (4<<6) // Dolby Digital AC3
-#define AF_FORMAT_S_IEC61937 (6<<6)
-#define AF_FORMAT_SPECIAL_MASK (7<<6)
-
-// Fixed or floating point
-#define AF_FORMAT_I (1<<9) // Int
-#define AF_FORMAT_F (2<<9) // Foating point
-#define AF_FORMAT_POINT_MASK (3<<9)
+#define AF_FORMAT_8BIT (0<<1)
+#define AF_FORMAT_16BIT (1<<1)
+#define AF_FORMAT_24BIT (2<<1)
+#define AF_FORMAT_32BIT (3<<1)
+#define AF_FORMAT_64BIT (4<<1)
+#define AF_FORMAT_BITS_MASK (7<<1)
+
+// Fixed/floating point/special
+#define AF_FORMAT_I (1<<4) // Int
+#define AF_FORMAT_F (2<<4) // Foating point
+#define AF_FORMAT_S (4<<4) // special (IEC61937)
+#define AF_FORMAT_TYPE_MASK (7<<4)
// Interleaving (planar formats have data for each channel in separate planes)
-#define AF_FORMAT_INTERLEAVED (0<<11) // must be 0
-#define AF_FORMAT_PLANAR (1<<11)
-#define AF_FORMAT_INTERLEAVING_MASK (1<<11)
+#define AF_FORMAT_INTERLEAVED (0<<7) // must be 0
+#define AF_FORMAT_PLANAR (1<<7)
+#define AF_FORMAT_INTERLEAVING_MASK (1<<7)
+
+#define AF_FORMAT_S_CODEC(n) ((n)<<8)
+#define AF_FORMAT_S_CODEC_MASK (15 <<8) // 16 codecs max.
#define AF_FORMAT_MASK ((1<<12)-1)
#define AF_INTP (AF_FORMAT_I|AF_FORMAT_PLANAR)
#define AF_FLTP (AF_FORMAT_F|AF_FORMAT_PLANAR)
+#define AF_FORMAT_S_(n) (AF_FORMAT_S_CODEC(n)|AF_FORMAT_S|AF_FORMAT_16BIT)
// actual sample formats
enum af_format {
@@ -78,27 +77,25 @@ enum af_format {
AF_FORMAT_FLOAT = (AF_FORMAT_F|AF_FORMAT_32BIT),
AF_FORMAT_DOUBLE = (AF_FORMAT_F|AF_FORMAT_64BIT),
- AF_FORMAT_AC3 = (AF_FORMAT_S_AC3|AF_FORMAT_16BIT),
- AF_FORMAT_IEC61937 = (AF_FORMAT_S_IEC61937|AF_FORMAT_16BIT),
- AF_FORMAT_MPEG2 = (AF_FORMAT_S_MPEG2),
-
// Planar variants
AF_FORMAT_U8P = (AF_INTP|AF_FORMAT_US|AF_FORMAT_8BIT),
AF_FORMAT_S16P = (AF_INTP|AF_FORMAT_SI|AF_FORMAT_16BIT),
AF_FORMAT_S32P = (AF_INTP|AF_FORMAT_SI|AF_FORMAT_32BIT),
AF_FORMAT_FLOATP = (AF_FLTP|AF_FORMAT_32BIT),
AF_FORMAT_DOUBLEP = (AF_FLTP|AF_FORMAT_64BIT),
-};
-#define AF_FORMAT_IS_AC3(fmt) \
- ((fmt) == AF_FORMAT_AC3)
-
-#define AF_FORMAT_IS_IEC61937(fmt) \
- (AF_FORMAT_IS_AC3(fmt) || \
- ((fmt) & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_S_IEC61937)
+ // All of these use IEC61937 framing, and otherwise pretend to be like PCM.
+ AF_FORMAT_S_AAC = AF_FORMAT_S_(0),
+ AF_FORMAT_S_AC3 = AF_FORMAT_S_(1),
+ AF_FORMAT_S_DTS = AF_FORMAT_S_(2),
+ AF_FORMAT_S_DTSHD = AF_FORMAT_S_(3),
+ AF_FORMAT_S_EAC3 = AF_FORMAT_S_(4),
+ AF_FORMAT_S_MP3 = AF_FORMAT_S_(5),
+ AF_FORMAT_S_TRUEHD = AF_FORMAT_S_(6),
+};
-#define AF_FORMAT_IS_SPECIAL(fmt) \
- ((fmt & AF_FORMAT_SPECIAL_MASK) != 0)
+#define AF_FORMAT_IS_IEC61937(f) (((f) & AF_FORMAT_TYPE_MASK) == AF_FORMAT_S)
+#define AF_FORMAT_IS_SPECIAL(f) AF_FORMAT_IS_IEC61937(f)
struct af_fmt_entry {
const char *name;