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
103 { "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, },103 { "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, },
104};104};
105 105
106#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
107static uint64_t get_channel_layout_single(const char *name, int name_len, int compat)
108#else
106static uint64_t get_channel_layout_single(const char *name, int name_len)109static uint64_t get_channel_layout_single(const char *name, int name_len)
110#endif
107{111{
108 int i;112 int i;
109 char *end;113 char *end;
@@ -120,16 +124,40 @@ static uint64_t get_channel_layout_single(const char *name, int name_len) · 10 unmodified lines
120 !memcmp(channel_names[i].name, name, name_len))124 !memcmp(channel_names[i].name, name, name_len))
121 return (int64_t)1 << i;125 return (int64_t)1 << i;
122 i = strtol(name, &end, 10);126 i = strtol(name, &end, 10);
123 if (end - name == name_len ||127
124 (end + 1 - name == name_len && *end == 'c'))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'))
125 return av_get_default_channel_layout(i);145 return av_get_default_channel_layout(i);
146#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
147 }
148#endif
149
126 layout = strtoll(name, &end, 0);150 layout = strtoll(name, &end, 0);
127 if (end - name == name_len)151 if (end - name == name_len)
128 return FFMAX(layout, 0);152 return FFMAX(layout, 0);
129 return 0;153 return 0;
130}154}
131 155
156#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
157uint64_t ff_get_channel_layout(const char *name, int compat)
158#else
132uint64_t av_get_channel_layout(const char *name)159uint64_t av_get_channel_layout(const char *name)
160#endif
133{161{
134 const char *n, *e;162 const char *n, *e;
135 const char *name_end = name + strlen(name);163 const char *name_end = name + strlen(name);
@@ -137,7 +165,11 @@ uint64_t av_get_channel_layout(const char *name) · 1 unmodified line
137 165
138 for (n = name; n < name_end; n = e + 1) {166 for (n = name; n < name_end; n = e + 1) {
139 for (e = n; e < name_end && *e != '+' && *e != '|'; e++);167 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
140 layout_single = get_channel_layout_single(n, e - n);171 layout_single = get_channel_layout_single(n, e - n);
172#endif
141 if (!layout_single)173 if (!layout_single)
142 return 0;174 return 0;
143 layout |= layout_single;175 layout |= layout_single;
@@ -145,6 +177,13 @@ uint64_t av_get_channel_layout(const char *name) · 1 unmodified line
145 return layout;177 return layout;
146}178}
147 179
180#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
181uint64_t av_get_channel_layout(const char *name)
182{
183 return ff_get_channel_layout(name, 1);
184}
185#endif
186
148void av_bprint_channel_layout(struct AVBPrint *bp,187void av_bprint_channel_layout(struct AVBPrint *bp,
149 int nb_channels, uint64_t channel_layout)188 int nb_channels, uint64_t channel_layout)
150{189{
libavutil/channel_layout.h+6−1
@@ -136,7 +136,12 @@ enum AVMatrixEncoding { · 135 unmodified lines
136 * - a channel layout mask, in hexadecimal starting with "0x" (see the136 * - a channel layout mask, in hexadecimal starting with "0x" (see the
137 * AV_CH_* macros).137 * AV_CH_* macros).
138 *138 *
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"
140 */145 */
141uint64_t av_get_channel_layout(const char *name);146uint64_t av_get_channel_layout(const char *name);
142 147
libavutil/internal.h+5−0
@@ -39,6 +39,7 @@ · 38 unmodified lines
39#include "timer.h"39#include "timer.h"
40#include "cpu.h"40#include "cpu.h"
41#include "dict.h"41#include "dict.h"
42#include "version.h"
42 43
43#if ARCH_X8644#if ARCH_X86
44# include "x86/emms.h"45# include "x86/emms.h"
@@ -219,4 +220,8 @@ void avpriv_request_sample(void *avc, · 174 unmodified lines
219 */220 */
220int avpriv_open(const char *filename, int flags, ...);221int avpriv_open(const char *filename, int flags, ...);
221 222
223#if FF_API_GET_CHANNEL_LAYOUT_COMPAT
224uint64_t ff_get_channel_layout(const char *name, int compat);
225#endif
226
222#endif /* AVUTIL_INTERNAL_H */227#endif /* AVUTIL_INTERNAL_H */
libavutil/version.h+3−0
@@ -138,6 +138,9 @@ · 137 unmodified lines
138#ifndef FF_API_VDPAU138#ifndef FF_API_VDPAU
139#define FF_API_VDPAU (LIBAVUTIL_VERSION_MAJOR < 53)139#define FF_API_VDPAU (LIBAVUTIL_VERSION_MAJOR < 53)
140#endif140#endif
141#ifndef FF_API_GET_CHANNEL_LAYOUT_COMPAT
142#define FF_API_GET_CHANNEL_LAYOUT_COMPAT (LIBAVUTIL_VERSION_MAJOR < 53)
143#endif
141 144
142/**145/**
143 * @}146 * @}

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