History

lavu/channel_layout: change av_get_channel_layout() behavior at the next bump

The new syntax is preferred since it allows backward syntax compatibility with libswr when switching to the new option handling code with AV_OPT_TYPE_CHANNEL_LAYOUT. With the new parser the string: 1234 is interpreted as a channel layout mask, rather than as a number of channels, and thus it's compatible with the current way to set a channel layout as an integer (e.g. for the icl and ocl options) making use of integer option values. ff_get_channel_layout() with compat=0 will be used in the AV_OPT_TYPE_CHANNEL handler code. The user is encouraged to switch to the new forward compatible syntax, which requires to put a trailing "c" when specifying a layout as a number of channels.

Stefano Sabatini committed 13 years ago

Commit d96e3771 parent b236eb44 files · +55 −3Browse files

Unified · Split

4 files
  1. libavutil/channel_layout.c +41 −2
  2. libavutil/channel_layout.h +6 −1
  3. libavutil/internal.h +5 −0
  4. libavutil/version.h +3 −0
libavutil/channel_layout.c+41−2
@@ -103,7 +103,11 @@ static const struct { · 102 unmodified lines
103103 { "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, },
104104 };
105105
106+#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
107+static uint64_t get_channel_layout_single(const char *name, int name_len, int compat)
108+#else
106109 static uint64_t get_channel_layout_single(const char *name, int name_len)
110+#endif
107111 {
108112 int i;
109113 char *end;
@@ -120,16 +124,40 @@ static uint64_t get_channel_layout_single(const char *name, int name_len) · 10 unmodified lines
120124 !memcmp(channel_names[i].name, name, name_len))
121125 return (int64_t)1 << i;
122126 i = strtol(name, &end, 10);
123− if (end - name == name_len ||
124− (end + 1 - name == name_len && *end == 'c'))
127+
128+#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
129+ if (compat) {
130+ if (end - name == name_len ||
131+ (end + 1 - name == name_len && *end == 'c')) {
132+ layout = av_get_default_channel_layout(i);
133+ if (end - name == name_len) {
134+ av_log(NULL, AV_LOG_WARNING,
135+ "Single channel layout '%.*s' is interpreted as a number of channels, "
136+ "switch to the syntax '%.*sc' otherwise it will be interpreted as a "
137+ "channel layout number in a later version\n",
138+ name_len, name, name_len, name);
139+ return layout;
140+ }
141+ }
142+ } else {
143+#endif
144+ if ((end + 1 - name == name_len && *end == 'c'))
125145 return av_get_default_channel_layout(i);
146+#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
147+ }
148+#endif
149+
126150 layout = strtoll(name, &end, 0);
127151 if (end - name == name_len)
128152 return FFMAX(layout, 0);
129153 return 0;
130154 }
131155
156+#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
157+uint64_t ff_get_channel_layout(const char *name, int compat)
158+#else
132159 uint64_t av_get_channel_layout(const char *name)
160+#endif
133161 {
134162 const char *n, *e;
135163 const char *name_end = name + strlen(name);
@@ -137,7 +165,11 @@ uint64_t av_get_channel_layout(const char *name) · 1 unmodified line
137165
138166 for (n = name; n < name_end; n = e + 1) {
139167 for (e = n; e < name_end && *e != '+' && *e != '|'; e++);
168+#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
169+ layout_single = get_channel_layout_single(n, e - n, compat);
170+#else
140171 layout_single = get_channel_layout_single(n, e - n);
172+#endif
141173 if (!layout_single)
142174 return 0;
143175 layout |= layout_single;
@@ -145,6 +177,13 @@ uint64_t av_get_channel_layout(const char *name) · 1 unmodified line
145177 return layout;
146178 }
147179
180+#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
181+uint64_t av_get_channel_layout(const char *name)
182+{
183+ return ff_get_channel_layout(name, 1);
184+}
185+#endif
186+
148187 void av_bprint_channel_layout(struct AVBPrint *bp,
149188 int nb_channels, uint64_t channel_layout)
150189 {
libavutil/channel_layout.h+6−1
@@ -136,7 +136,12 @@ enum AVMatrixEncoding { · 135 unmodified lines
136136 * - a channel layout mask, in hexadecimal starting with "0x" (see the
137137 * AV_CH_* macros).
138138 *
139− * Example: "stereo+FC" = "2+FC" = "2c+1c" = "0x7"
139+ * @warning Starting from the next major bump the trailing character
140+ * 'c' to specify a number of channels will be required, while a
141+ * channel layout mask could also be specified as a decimal number
142+ * (if and only if not followed by "c").
143+ *
144+ * Example: "stereo+FC" = "2c+FC" = "2c+1c" = "0x7"
140145 */
141146 uint64_t av_get_channel_layout(const char *name);
142147
libavutil/internal.h+5−0
@@ -39,6 +39,7 @@ · 38 unmodified lines
3939 #include "timer.h"
4040 #include "cpu.h"
4141 #include "dict.h"
42+#include "version.h"
4243
4344 #if ARCH_X86
4445 # include "x86/emms.h"
@@ -219,4 +220,8 @@ void avpriv_request_sample(void *avc, · 174 unmodified lines
219220 */
220221 int avpriv_open(const char *filename, int flags, ...);
221222
223+#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
224+uint64_t ff_get_channel_layout(const char *name, int compat);
225+#endif
226+
222227 #endif /* AVUTIL_INTERNAL_H */
libavutil/version.h+3−0
@@ -138,6 +138,9 @@ · 137 unmodified lines
138138 #ifndef FF_API_VDPAU
139139 #define FF_API_VDPAU (LIBAVUTIL_VERSION_MAJOR < 53)
140140 #endif
141+#ifndef FF_API_GET_CHANNEL_LAYOUT_COMPAT
142+#define FF_API_GET_CHANNEL_LAYOUT_COMPAT (LIBAVUTIL_VERSION_MAJOR < 53)
143+#endif
141144
142145 /**
143146 * @}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t