Browse code

flac muxer: write WAVEFORMATEXTENSIBLE_CHANNEL_MASK tag for multichannel files

Anton Khirnov authored on 2014/05/25 18:34:32
Showing 3 changed files
... ...
@@ -19,6 +19,7 @@
19 19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 20
  */
21 21
 
22
+#include "libavutil/channel_layout.h"
22 23
 #include "libavutil/opt.h"
23 24
 #include "libavcodec/flac.h"
24 25
 #include "avformat.h"
... ...
@@ -83,6 +84,23 @@ static int flac_write_header(struct AVFormatContext *s)
83 83
     if (ret)
84 84
         return ret;
85 85
 
86
+    /* add the channel layout tag */
87
+    if (codec->channel_layout &&
88
+        !(codec->channel_layout & ~0x3ffffULL) &&
89
+        !ff_flac_is_native_layout(codec->channel_layout)) {
90
+        AVDictionaryEntry *chmask = av_dict_get(s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK",
91
+                                                NULL, 0);
92
+
93
+        if (chmask) {
94
+            av_log(s, AV_LOG_WARNING, "A WAVEFORMATEXTENSIBLE_CHANNEL_MASK is "
95
+                   "already present, this muxer will not overwrite it.\n");
96
+        } else {
97
+            uint8_t buf[32];
98
+            snprintf(buf, sizeof(buf), "0x%"PRIx64, codec->channel_layout);
99
+            av_dict_set(&s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
100
+        }
101
+    }
102
+
86 103
     ret = flac_write_block_comment(s->pb, &s->metadata, 0,
87 104
                                    s->flags & AVFMT_FLAG_BITEXACT);
88 105
     if (ret)
... ...
@@ -29,4 +29,6 @@
29 29
 int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec,
30 30
                          int last_block);
31 31
 
32
+int ff_flac_is_native_layout(uint64_t channel_layout);
33
+
32 34
 #endif /* AVFORMAT_FLACENC_H */
... ...
@@ -19,6 +19,8 @@
19 19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 20
  */
21 21
 
22
+#include "libavutil/channel_layout.h"
23
+
22 24
 #include "libavcodec/flac.h"
23 25
 #include "libavcodec/bytestream.h"
24 26
 #include "avformat.h"
... ...
@@ -45,3 +47,17 @@ int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec,
45 45
 
46 46
     return 0;
47 47
 }
48
+
49
+int ff_flac_is_native_layout(uint64_t channel_layout)
50
+{
51
+    if (channel_layout == AV_CH_LAYOUT_MONO     ||
52
+        channel_layout == AV_CH_LAYOUT_STEREO   ||
53
+        channel_layout == AV_CH_LAYOUT_SURROUND ||
54
+        channel_layout == AV_CH_LAYOUT_QUAD     ||
55
+        channel_layout == AV_CH_LAYOUT_5POINT0  ||
56
+        channel_layout == AV_CH_LAYOUT_5POINT1  ||
57
+        channel_layout == AV_CH_LAYOUT_6POINT1  ||
58
+        channel_layout == AV_CH_LAYOUT_7POINT1)
59
+        return 1;
60
+    return 0;
61
+}